package cc.rengu.redp.bizimpl.upmp.service.impl;

import cc.rengu.igas.bomp.facade.*;
import cc.rengu.igas.bomp.facade.bean.*;
import cc.rengu.igas.bomp.facade.enums.BompAuditFlagEnum;
import cc.rengu.igas.bomp.facade.enums.BompManageOprTypeEnum;
import cc.rengu.igas.bomp.facade.request.*;
import cc.rengu.igas.bomp.facade.response.*;
import cc.rengu.igas.bomp.facade.result.Result;
import cc.rengu.redp.bizimpl.bean.LabelValueBean;
import cc.rengu.redp.bizimpl.constant.UpmpConstant;
import cc.rengu.redp.bizimpl.csmc.service.ICMchntRiskFundInfoService;
import cc.rengu.redp.bizimpl.enums.*;
import cc.rengu.redp.bizimpl.igas.vo.OnlineVerificationVO;
import cc.rengu.redp.bizimpl.igas.vo.PTxnAuthMap;
import cc.rengu.redp.bizimpl.igas.vo.PTxnGroup;
import cc.rengu.redp.bizimpl.igas.vo.SettleAcctInfoVO;
import cc.rengu.redp.bizimpl.upmp.common.BusinessContainer;
import cc.rengu.redp.bizimpl.upmp.dao.UpmpBMchntBaseInfoMapper;
import cc.rengu.redp.bizimpl.upmp.domain.*;
import cc.rengu.redp.bizimpl.upmp.service.*;
import cc.rengu.redp.bizimpl.upmp.vo.*;
import cc.rengu.redp.bizimpl.utils.*;
import cc.rengu.redp.common.domain.QueryRequest;
import cc.rengu.redp.common.exception.RedpException;
import cc.rengu.redp.common.utils.DateUtil;
import cc.rengu.redp.common.utils.SortUtil;
import com.alibaba.fastjson.JSON;
import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.dubbo.config.annotation.DubboReference;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.stream.Collectors;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author 刘玉亮.LL
 * @since 2021-06-22
 */
@Slf4j
@Service
@DS("upmp")
public class UpmpBMchntBaseInfoServiceImpl extends ServiceImpl<UpmpBMchntBaseInfoMapper, UpmpBMchntBaseInfo> implements IUpmpBMchntBaseInfoService {
    @Autowired
    private IUpmpSysParamService upmpSysParamService;
    @Autowired
    private IUpmpOrganizationService organizationService;
    @Autowired
    private IUpmpSysSeqService upmpSysSeqService;
    @Autowired
    private IUpmpBPlatMchntInfoService platMchntInfoService;
    @Autowired
    private IndustryInfoService industryInfoService;
    @Autowired
    private MerGrpInfoService merGrpInfoService;
    @Autowired
    private IUpmpMarketInfoService marketInfoService;
    @Autowired
    private IUpmpBTradeAreaInfoService tradeAreaInfoService;
    @Autowired
    private IUpmpBAgentInfoService agentInfoService;
    @Autowired
    private IUpmpBMchntLevelInfoService mchntLevelInfoService;
    @Autowired
    private IUpmpPrivilegeCheckService upmpPrivilegeCheckService;
    @Autowired
    private IUpmpBMchntSignInfoService bMchntSignInfoService;
    @Autowired
    private IUpmpBMchntImageInfoService bMchntImageInfoService;
    @Autowired
    private IUpmpBMchntAcctInfoService bMchntAcctInfoService;
    @Autowired
    private IUpmpBMchntProdInfoService bMchntProdInfoService;
    @Autowired
    private IUpmpBMchntFeeInfoService bMchntFeeInfoService;
    @Autowired
    private IUpmpBMchntBlacklistInfoService mchntBlackListInfoService;
    @Autowired
    private IBizHisService bizHisService;
    @Autowired
    private RegionInfoService regionInfoService;
    @Autowired
    private UpmpBMchntBaseInfoMapper upmpBMchntBaseInfoMapper;
    @Autowired
    private ICMchntRiskFundInfoService riskFundInfoService;
    @Autowired
    private IUpmpUserInfoService upmpUserInfoService;


//    @DubboReference(version = "2.2.0",url = "dubbo://172.17.100.9:62132",check = false)
  @DubboReference(version = "${dubbo.protocol.version}", check = false)
    private BompMchntManageService bompMchntManageService;

//    @DubboReference(version = "2.2.0", url = "dubbo://172.17.100.9:62132", check = false)
  @DubboReference(version = "${dubbo.protocol.version}", check = false)
    private BompMchntQueryService bompMchntQueryService;

//    @DubboReference(version = "2.2.0",url = "dubbo://172.17.100.9:62132",check = false)
  @DubboReference(version = "${dubbo.protocol.version}", check = false)
    private BompPublicQueryService bompPublicQueryService;

//    @DubboReference(version = "2.2.0",url = "dubbo://172.17.100.9:62132",check = false)
  @DubboReference(version = "${dubbo.protocol.version}", check = false)
    private BompThirdMchntEntryService bompThirdMchntEntryService;

//    @DubboReference(version = "2.2.0",url = "dubbo://172.17.100.9:62132",check = false)
  @DubboReference(version = "${dubbo.protocol.version}", check = false)
    private BompMchntPublicDealService bompMchntPublicDealService;


    private String oprMenuId = "20000030";
    private String oprMenuName = "商户管理:统一支付平台商户管理";
    private String oprBtnNamePrefix = "统一支付平台商户管理";
    private String webNextUrl = "bizimpl/upmp/merchantBaseInfo/MerchantBaseInfoOperation";

    @Override
    public String getOprMenuId() {
        return oprMenuId;
    }

    @Override
    public String getOprMenuName() {
        return oprMenuName;
    }

    @Override
    public String getWebNextUrl() {
        return webNextUrl;
    }

    @Override
    public String getOprBtnNamePrefix() {
        return oprBtnNamePrefix;
    }

    /**
     * 生成商户订单号（格式：MCMP + 8位日期 + 8位顺序号）
     */
    @Override
    public synchronized String genMerOrder(String instid) {
        // 获取渠道ID：固定20
        String channelId = CommonUtils.getChannelId(upmpSysParamService, instid);
        // 代理商编码前缀：MO（merOrder简写）
        String prefix = instid + "MCMP";
        // 自动生成一级代码
        String paramCode = BusinessContainer.COMM_PARAM_CODE;
        // 生成序列号
        String seqNum = upmpSysSeqService.updateParamValue(paramCode, "MER_ORDER", channelId);
        // 8位日期
        String date17 = DateUtils.formatDate(new Date(), DateUtils.FULL_SEQ_FORMAT);
        // 商户订单号
        String merOrder = prefix + date17 + String.format("%08d", Integer.parseInt(seqNum));
        return merOrder;
    }

    @Override
    public List<UpmpBMchntBaseInfo> getBMchntBaseInfoByGroupMchntNo(String groupMchntNo) {
        LambdaQueryWrapper<UpmpBMchntBaseInfo> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(UpmpBMchntBaseInfo::getGroupMchntNo, groupMchntNo);
        wrapper.eq(UpmpBMchntBaseInfo::getMchntStatus, "01");
        return this.list(wrapper);
    }

    @Override
    public UpmpBMchntBaseInfo findByMchntNo(String mchntNo) {
        LambdaQueryWrapper<UpmpBMchntBaseInfo> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(UpmpBMchntBaseInfo::getMchntNo, mchntNo);
        return baseMapper.selectOne(wrapper);
    }

    @Override
    public String selectByMchntNo(String mchntNo) {
        LambdaQueryWrapper<UpmpBMchntBaseInfo> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(UpmpBMchntBaseInfo::getMchntNo, mchntNo);
        List<UpmpBMchntBaseInfo> list = baseMapper.selectList(wrapper);
        if (list.size() == 0) {
            return "";
        }
        String managerName = "";
        if (list.get(0).getManagerName() != null) {
            managerName = list.get(0).getManagerName();
        }
        String contactName = "";
        if (list.get(0).getMchntContactName() != null) {
            contactName = list.get(0).getMchntContactName();
        }
        String contactPhone = "";
        if (list.get(0).getMchntContactPhone() != null) {
            contactPhone = list.get(0).getMchntContactPhone();
        }

        return list.get(0).getMchntType() + ";" + managerName + ";" + list.get(0).getMchntExpandTime() + ";"
                + contactName + ";" + contactPhone + ";" + list.get(0).getMchntStatus() + ";" + list.get(0).getAuditStatus();

    }

    @Override
    public IPage<MchntInfoBean> findByPage(QueryRequest request, UpmpBMchntBaseInfo info) throws RedpException {
        // 获取当前登录用户信息
        UpmpUserInfoVO user = CommonUtils.getCurrentUser(upmpSysParamService);
        if (Common.isBlank(info.getInstId())) {
            if (Common.isNotBlank(user) && Common.isNotBlank(user.getInstId())) {
                info.setInstId(user.getInstId());
            }
        }
        if (Common.isNotBlank(user) && Common.isNotBlank(user.getInstId())
                && !user.isAdmin() && !info.getInstId().equals(user.getInstId())) {
            log.error("查询商户信息列表请求参数与用户身份不符");
            throw new RedpException("查询商户信息列表请求参数与用户身份不符");
        }
        MchntInfoListQueryRequest req = new MchntInfoListQueryRequest();
        BeanUtils.copyProperties(info, req);
        req.setPageSize(request.getPageSize());
        req.setPageIndex(request.getPageNum() - 1);//联机页码从0开始，select2页码从1开始
        String traceNo = this.genMerOrder(info.getInstId());
        MchntInfoListQueryResponse resp = mchntInfoListQuery(info.getInstId(), user, req, traceNo);
        Page<MchntInfoBean> page = new Page<>();
        SortUtil.handlePageSort(request, page, true);
        List<MchntInfoBean> list = Lists.newArrayList();
        if (Common.isNotBlank(resp) && CollectionUtils.isNotEmpty(resp.getMchntInfoList())) {
            list = resp.getMchntInfoList();
            for (MchntInfoBean mchntInfoBean : list) {
                String createTime = mchntInfoBean.getCreateTime();
                String lastAuditTime = mchntInfoBean.getLastAuditTime();
                if (Common.isNotBlank(createTime) &&  createTime.contains(".")  ) {
                    int indexOf = createTime.indexOf(".");
                    createTime = createTime.substring(0, indexOf);
                }
                if (Common.isNotBlank(lastAuditTime)  &&  lastAuditTime.contains(".")) {
                    int indexOf = lastAuditTime.indexOf(".");
                    lastAuditTime = lastAuditTime.substring(0, indexOf);
                }
                mchntInfoBean.setCreateTime(createTime);
                mchntInfoBean.setLastAuditTime(lastAuditTime);
            }

            page.setRecords(list);
            page.setTotal(resp.getTotalRows());
        } else {
            page.setRecords(list);
            page.setTotal(0);
        }
        return page;
    }

    @Override
    public UpmpBMchntBaseInfo editTabs(UpmpBMchntBaseInfo info) throws RedpException {
        // 获取当前登录用户信息
        UpmpUserInfoVO user = CommonUtils.getCurrentUser(upmpSysParamService);
        if (Common.isBlank(info.getInstId())) {
            if (Common.isNotBlank(user) && Common.isNotBlank(user.getInstId())) {
                info.setInstId(user.getInstId());
            }
        }
        if (!info.getOptFlag().equals("add")) {
            MchntBaseInfoQueryResponse mchntBase = this.mchntBaseInfoQuery(info.getInstId(), user, genMerOrder(info.getInstId()), info.getMchntNo(), info.getMchntName(), BompQueryTypeEnum.REAL, bompMchntQueryService);
            MchntBaseInfoBean mchntBaseInfo = mchntBase.getMchntBaseInfo();
            info.setMchntType(mchntBaseInfo.getMchntType());
            info.setIndependentDataFlag(mchntBaseInfo.getIndependentDataFlag());
        }

        return info;
    }

    @Override
    public Map<String, Object> editShow(UpmpBMchntBaseInfo entity) throws RedpException {
        Map<String, Object> result = new HashMap<>();
        // 获取当前登录用户信息
        UpmpUserInfoVO user = CommonUtils.getCurrentUser(upmpSysParamService);
        if (PageOptFlagEnum.OPT_FLAG_ADD.getType().equals(entity.getOptFlag())) {
            if (!user.isAdmin()) {
                entity.setSignInstId(user.getOrgCode());
            } else {
                UpmpOrganization headOrgByCode = organizationService.getHeadOrgByCode(entity.getInstId());
                entity.setSignInstId(headOrgByCode == null ? user.getOrgCode() : headOrgByCode.getOrgCode());
            }
            entity.setMchntNo(BusinessContainer.INIT_MCHNT_NO);
            entity.setMchntAttr("01");
            entity.setMchntExpandType("03");
            entity.setMchntStatus(BizDataStatusEnum.STATUS_DRAFT.getType());
            entity.setAuditStatus(BizDataAuditStatusEnum.AUDIT_STATUS_ADD_NOTCOMMIT.getType());
            entity.setMchntExpandTime(DateUtils.formatDate(new Date(), "yyyy-MM-dd HH:mm:ss.SSS"));
            entity.setOprId(user.getId());


        } else if (PageOptFlagEnum.OPT_FLAG_UPDATE.getType().equals(entity.getOptFlag())
                || PageOptFlagEnum.OPT_FLAG_USE.getType().equals(entity.getOptFlag())
                || PageOptFlagEnum.OPT_FLAG_STOP.getType().equals(entity.getOptFlag())
                || PageOptFlagEnum.OPT_FLAG_CANCEL.getType().equals(entity.getOptFlag())
                || PageOptFlagEnum.OPT_FLAG_VIEW.getType().equals(entity.getOptFlag())) {//查询正式表数据
            //查询商户状态是否是新增退回、修改退回
            MchntBaseInfoQueryResponse mchntBase = mchntBaseInfoQuery(entity.getInstId(), user, genMerOrder(entity.getInstId()), entity.getMchntNo(), entity.getMchntName(), BompQueryTypeEnum.REAL, bompMchntQueryService);
            if (Common.isBlank(mchntBase)) {
                throw new RedpException("商户号[" + entity.getMchntNo() + "]没有查询到对应的商户信息");
            }

            if ((BizDataAuditStatusEnum.AUDIT_STATUS_UPD_CHECKING.getType().equals(mchntBase.getAuditStatus())
                    || BizDataAuditStatusEnum.AUDIT_STATUS_STOP_CHECKING.getType().equals(mchntBase.getAuditStatus())
                    || BizDataAuditStatusEnum.AUDIT_STATUS_USE_CHECKING.getType().equals(mchntBase.getAuditStatus())
                    || BizDataAuditStatusEnum.AUDIT_STATUS_CANCEL_CHECKING.getType().equals(mchntBase.getAuditStatus()))
                    && !PageOptFlagEnum.OPT_FLAG_VIEW.getType().equals(entity.getOptFlag())
                    && !PageOptFlagEnum.OPT_FLAG_CHECK.getType().equals(entity.getOptFlag())
                    && !PageOptFlagEnum.OPT_FLAG_CHECK_VIEW.getType().equals(entity.getOptFlag())) {
                throw new RedpException("商户号[" + entity.getMchntNo() + "]的商户信息已被审批流程锁定！");
            }
            if (PageOptFlagEnum.OPT_FLAG_UPDATE.getType().equals(entity.getOptFlag())
                    && (BizDataAuditStatusEnum.AUDIT_STATUS_UPD_REJECT.getType().equals(mchntBase.getAuditStatus()) || BizDataAuditStatusEnum.AUDIT_STATUS_ADD_REJECT.getType().equals(mchntBase.getAuditStatus())
                    || BizDataAuditStatusEnum.AUDIT_STATUS_UPD_NOTCOMMIT.getType().equals(mchntBase.getAuditStatus()) || BizDataAuditStatusEnum.AUDIT_STATUS_ADD_NOTCOMMIT.getType().equals(mchntBase.getAuditStatus())
                    || BizDataStatusEnum.STATUS_DRAFT.getType().equals(mchntBase.getMchntStatus()))) {
                //新增、修改拒绝时查询临时表数据
                mchntBase = mchntBaseInfoQuery(entity.getInstId(), user, genMerOrder(entity.getInstId()), entity.getMchntNo(), entity.getMchntName(), BompQueryTypeEnum.TEMP, bompMchntQueryService);
            }
            BeanUtils.copyProperties(mchntBase, entity);
            BeanUtils.copyProperties(mchntBase.getMchntBaseInfo(), entity);
            BeanUtils.copyProperties(mchntBase.getMchntContactsInfo(), entity);
            MchntContactsInfoBean contactsInfo = mchntBase.getMchntContactsInfo();
            entity.setMchntContactName(contactsInfo.getContactName());
            entity.setMchntContactCertType(contactsInfo.getContactCertType());
            entity.setMchntContactCertNo(contactsInfo.getContactCertNo());
            entity.setMchntContactPhone(contactsInfo.getContactPhone());
            entity.setMchntContactMobile(contactsInfo.getContactMobile());
            entity.setMchntContactEmail(contactsInfo.getContactEmail());
        } else if (PageOptFlagEnum.OPT_FLAG_CHECK.getType().equals(entity.getOptFlag()) || PageOptFlagEnum.OPT_FLAG_CHECK_VIEW.getType().equals(entity.getOptFlag())) {//查询临时表数据

            MchntBaseInfoQueryResponse mchntBaseTmp = mchntBaseInfoQuery(entity.getInstId(), user, genMerOrder(entity.getInstId()), entity.getMchntNo(), entity.getMchntName(), BompQueryTypeEnum.TEMP, bompMchntQueryService);
            BeanUtils.copyProperties(mchntBaseTmp, entity);
            BeanUtils.copyProperties(mchntBaseTmp.getMchntBaseInfo(), entity);
            BeanUtils.copyProperties(mchntBaseTmp.getMchntContactsInfo(), entity);
//          detach(entity);
            //TODO 审核对比功能暂时屏蔽
            //查询商户状态临时表正式表数据用于比较
/*
            if (BizDataAuditStatusEnum.AUDIT_STATUS_UPD_CHECKING.getType().equals(mchntBaseTmp.getAuditStatus())) {
                MchntBaseInfoQueryResponse mchntBase = mchntBaseInfoQuery(entity.getInstId(), user, genMerOrder(entity.getInstId()), entity.getMchntNo(), entity.getMchntName(), BompQueryTypeEnum.REAL, bompMchntQueryService);
                UpmpBMchntBaseInfo entityReal = new UpmpBMchntBaseInfo();
                entityReal.setInstId(entity.getInstId());
                BeanUtils.copyProperties(mchntBase, entityReal);
                BeanUtils.copyProperties(mchntBase.getMchntBaseInfo(), entityReal);
                BeanUtils.copyProperties(mchntBase.getMchntContactsInfo(), entityReal);
                MchntContactsInfoBean contactsInfo = mchntBase.getMchntContactsInfo();
                entityReal.setMchntContactName(contactsInfo.getContactName());
                entity.setMchntContactCertType(contactsInfo.getContactCertType());
                entityReal.setMchntContactCertNo(contactsInfo.getContactCertNo());
                entityReal.setMchntContactPhone(contactsInfo.getContactPhone());
                entityReal.setMchntContactMobile(contactsInfo.getContactMobile());
                entityReal.setMchntContactEmail(contactsInfo.getContactEmail());
                List<LabelValueBean> compareBeans = CommonUtils.compareData(entity, entityReal, UpmpBMchntBaseInfo.class);
                for (LabelValueBean bean : compareBeans) {
                    if (Common.isNotBlank(bean.getValue())) {
                        String beanVal = bean.getValue();
                        if ("mchntType".equals(bean.getElabel())) {
                            beanVal = bean.getValue() + "-" + EnumUtils.getEnumDescriotionByValue(bean.getValue(), MchntTypeEnum.class, "getType", "getDesc");
                        } else if ("mchntLevel".equals(bean.getElabel())) {
                            beanVal = bean.getValue() + "-" + getMchntLevelName(entity.getInstId(), user, bean.getValue(), bompMchntQueryService, genMerOrder(entity.getInstId()));
                        } else if ("smsFlag".equals(bean.getElabel())) {
                            beanVal = bean.getValue() + "-" + EnumUtils.getEnumDescriotionByValue(bean.getValue(), IgasYesOrNoEnum.class, "getType", "getDesc");
                        } else if ("mchntNature".equals(bean.getElabel())) {
                            beanVal = bean.getValue() + "-" + EnumUtils.getEnumDescriotionByValue(bean.getValue(), BompMchntNatureEnum.class, "getType", "getDesc");
                        } else if ("managementScope".equals(bean.getElabel())) {
                            beanVal = bean.getValue() + "-" + EnumUtils.getEnumDescriotionByValue(bean.getValue(), MchntManagementScopeEnum.class, "getType", "getDesc");
                        } else if ("industryType".equals(bean.getElabel())) {
                            beanVal = bean.getValue() + "-" + getIndustryTypeCname(entity.getInstId(), user, bean.getValue(), bompPublicQueryService, genMerOrder(entity.getInstId()));
                        } else if ("independentDataFlag".equals(bean.getElabel())) {
                            beanVal = bean.getValue() + "-" + EnumUtils.getEnumDescriotionByValue(bean.getValue(), IgasYesOrNoEnum.class, "getType", "getDesc");
                        } else if ("chainMchntNo".equals(bean.getElabel())) {
                            beanVal = bean.getValue() + "-" + getMchntCname(entity.getInstId(), user, bean.getValue(), BompQueryTypeEnum.REAL, bompMchntQueryService, genMerOrder(entity.getInstId()));
                        } else if ("platMchntNo".equals(bean.getElabel())) {
                            beanVal = bean.getValue() + "-" + getPlatMchntName(entity.getInstId(), user, bean.getValue(), bompMchntQueryService, genMerOrder(entity.getInstId()));
                        } else if ("groupMchntNo".equals(bean.getElabel())) {
                            beanVal = bean.getValue() + "-" + getGroupMchntName(entity.getInstId(), user, bean.getValue(), bompMchntQueryService, genMerOrder(entity.getInstId()));
                        } else if ("mchntArea".equals(bean.getElabel())) {
                            beanVal = bean.getValue() + "-" + getMchntAreaName(entity.getInstId(), user, bean.getValue(), bompMchntQueryService, genMerOrder(entity.getInstId()));
                        } else if ("marketFlag".equals(bean.getElabel())) {
                            beanVal = bean.getValue() + "-" + EnumUtils.getEnumDescriotionByValue(bean.getValue(), IgasYesOrNoEnum.class, "getType", "getDesc");
                        } else if ("agentMchntNo".equals(bean.getElabel())) {
                            beanVal = bean.getValue() + "-" + getAgentMchntName(entity.getInstId(), user, bean.getValue(), bompMchntQueryService, genMerOrder(entity.getInstId()));
                        } else if ("contactCertType".equals(bean.getElabel())) {
                            beanVal = bean.getValue() + "-" + EnumUtils.getEnumDescriotionByValue(bean.getValue(), BompArtifCertTypeEnum.class, "getType", "getDesc");
                        } else if ("reconMailFlag".equals(bean.getElabel())) {
                            beanVal = bean.getValue() + "-" + EnumUtils.getEnumDescriotionByValue(bean.getValue(), IgasYesOrNoEnum.class, "getType", "getDesc");
                        } else if ("mchntAttr".equals(bean.getElabel())) {
                            beanVal = bean.getValue() + "-" + EnumUtils.getEnumDescriotionByValue(bean.getValue(), BompMchntAttributeEnum.class, "getType", "getDesc");
                        } else if ("mchntSignType".equals(bean.getElabel())) {
                            beanVal = bean.getValue() + "-" + EnumUtils.getEnumDescriotionByValue(bean.getValue(), IgasYesOrNoEnum.class, "getType", "getDesc");
                        } else if ("supportCreditFlag".equals(bean.getElabel())) {
                            beanVal = bean.getValue() + "-" + EnumUtils.getEnumDescriotionByValue(bean.getValue(), IgasYesOrNoEnum.class, "getType", "getDesc");
                        } else if ("noPasswordFlag".equals(bean.getElabel())) {
                            beanVal = bean.getValue() + "-" + EnumUtils.getEnumDescriotionByValue(bean.getValue(), IgasYesOrNoEnum.class, "getType", "getDesc");
                        } else if ("mchntDelayFlag".equals(bean.getElabel())) {
                            beanVal = bean.getValue() + "-" + EnumUtils.getEnumDescriotionByValue(bean.getValue(), IgasYesOrNoEnum.class, "getType", "getDesc");
                        } else if ("mchntBizProvince".equals(bean.getElabel())) {
                            beanVal = bean.getValue() + "-" + (Common.isBlank(mchntBase.getMchntBaseInfo().getMchntBizProvinceName()) ? "" : mchntBase.getMchntBaseInfo().getMchntBizProvinceName());
                        } else if ("mchntBizCity".equals(bean.getElabel())) {
                            beanVal = bean.getValue() + "-" + (Common.isBlank(mchntBase.getMchntBaseInfo().getMchntBizCityName()) ? "" : mchntBase.getMchntBaseInfo().getMchntBizCityName());
                        } else if ("mchntBizRegion".equals(bean.getElabel())) {
                            beanVal = bean.getValue() + "-" + (Common.isBlank(mchntBase.getMchntBaseInfo().getMchntBizRegionName()) ? "" : mchntBase.getMchntBaseInfo().getMchntBizRegionName());
                        }
                        bean.setValue(beanVal);
                    }
                }
                result.put("compareBeans", JSON.toJSONString(compareBeans));
            }
*/
        } else {
            log.error("不支持的操作");
            throw new RedpException("不支持的操作");
        }

        //调用系统参数查询接口 查看法人行是否配置展示所属商圈
        ParamQueryRequest req = new ParamQueryRequest();
        req.setUserId(user.getId());
        req.setParamKey(ParamQueryKeyEnum.MCHNT_AREA.getType());
        req.setParamType(BusinessContainer.MCMP_TO_BOMP_PARAM_TYPE);
        try {
            ParamQueryResponse paramQueryResponse = paramQuery(entity.getInstId(), req, genMerOrder(entity.getInstId()));
            if (Common.isNotBlank(paramQueryResponse)) {
                List<SysParamBean> sysParamList = paramQueryResponse.getSysParamList();
                if (CollectionUtils.isNotEmpty(sysParamList)) {
                    result.put("mchntArea", sysParamList.get(0).getParamValue());
                }
            }
        } catch (Exception e) {
            log.info(e.getMessage());
        }


        //是否支持自助开展营销活动
        ParamQueryRequest req1 = new ParamQueryRequest();
        req1.setUserId(user.getId());
        req1.setParamKey(ParamQueryKeyEnum.MARKET_FLAG.getType());
        req1.setParamType(BusinessContainer.MCMP_TO_BOMP_PARAM_TYPE);
        try {
            ParamQueryResponse paramQueryResponse1 = paramQuery(entity.getInstId(), req1, genMerOrder(entity.getInstId()));
            if (Common.isNotBlank(paramQueryResponse1)) {
                List<SysParamBean> sysParamList = paramQueryResponse1.getSysParamList();
                if (CollectionUtils.isNotEmpty(sysParamList)) {
                    result.put("marketFlag", sysParamList.get(0).getParamValue());
                }
            }
        } catch (Exception e) {
            log.info(e.getMessage());
        }


        //代理机构是否展示
        ParamQueryRequest req3 = new ParamQueryRequest();
        req3.setUserId(user.getId());
        req3.setParamKey(ParamQueryKeyEnum.AGENT_MCHNT_NO.getType());
        req3.setParamType(BusinessContainer.MCMP_TO_BOMP_PARAM_TYPE);
        try {
            ParamQueryResponse paramQueryResponse3 = paramQuery(entity.getInstId(), req3, genMerOrder(entity.getInstId()));
            if (Common.isNotBlank(paramQueryResponse3)) {
                List<SysParamBean> sysParamList = paramQueryResponse3.getSysParamList();
                if (CollectionUtils.isNotEmpty(sysParamList)) {
                    result.put("AGENTMCHNTNO", sysParamList.get(0).getParamValue());
                }
            }
        } catch (Exception e) {
            log.info(e.getMessage());
        }

        ParamQueryRequest req4 = new ParamQueryRequest();
        req4.setUserId(user.getId());
        req4.setParamKey("SMS_SEND_FLAG");
        req4.setParamType("SMS_SWITCH_PARAM");
        try {
            ParamQueryResponse paramQueryResponse4 = paramQuery(entity.getInstId(), req4, genMerOrder(entity.getInstId()));
            if (Common.isNotBlank(paramQueryResponse4)) {
                List<SysParamBean> sysParamList = paramQueryResponse4.getSysParamList();
                if (CollectionUtils.isNotEmpty(sysParamList)) {
                    String paramValue = sysParamList.get(0).getParamValue();
                    if (paramValue.equals("Y") && Common.isBlank(entity.getSmsFlag())) {
                        entity.setSmsFlag("Y");
                    } else if (!paramValue.equals("Y")) {
                        entity.setSmsFlag("N");
                    }
                    result.put("SMSSENDFLAG", paramValue);
                } else {
                    entity.setSmsFlag("N");
                }
            }
        } catch (Exception e) {
            log.info(e.getMessage());
        }

        //新增时查询系统参数获取总行所在省
        if (Common.isBlank(entity.getMchntBizProvince())) {
            ParamQueryRequest instprovincereq = new ParamQueryRequest();
            instprovincereq.setUserId(user.getId());
            instprovincereq.setParamKey(entity.getInstId());
            instprovincereq.setParamType("INST_PROVINCE");
            try {
                ParamQueryResponse queryResponse = paramQuery(entity.getInstId(), instprovincereq, genMerOrder(entity.getInstId()));
                List<SysParamBean> sysParamList1 = queryResponse.getSysParamList();
                if (CollectionUtils.isNotEmpty(sysParamList1)) {
                    entity.setMchntBizProvince(sysParamList1.get(0).getParamValue());
                }
            } catch (Exception e) {
                log.info(e.getMessage());
            }

        }

        //平台商户
       /* if (StringUtils.isNotBlank(entity.getPlatMchntNo())) {
            UpmpBPlatMchntInfo platmchntinfo = platMchntInfoService.findOneByCode(entity.getPlatMchntNo(), BusinessContainer.data_sta_01, entity.getInstId());
            if (null != platmchntinfo) {
                result.put("platmchntname", platmchntinfo.getPlatMchntName());
            }
        }

        //行业类别
        if (StringUtils.isNotBlank(entity.getIndustryType())) {
            IndustryInfo industryinfo = industryInfoService.findOneByCode(entity.getIndustryType(), BusinessContainer.data_sta_01);
            if (null != industryinfo) {
                result.put("industryName", industryinfo.getIndustryName());
            }
        }
        //经营范围
        if (StringUtils.isNotBlank(entity.getManagementScope())) {
            MerGrpInfo mergrpinfo = merGrpInfoService.findOneByManagementScope(entity.getManagementScope(), BusinessContainer.data_sta_01);
            if (null != mergrpinfo) {
                result.put("grpDesc", mergrpinfo.getGrpDesc());
            }
        }
        //集团商户
        if (StringUtils.isNotBlank(entity.getGroupMchntNo())) {
            UpmpMarketInfo marketInfo = marketInfoService.findOneByCode(entity.getGroupMchntNo(), BusinessContainer.data_sta_01, entity.getInstId());
            if (null != marketInfo) {
                result.put("groupMchntName", marketInfo.getGroupMchntName());
            }
        }
        //所属商圈
        if (StringUtils.isNotBlank(entity.getMchntArea())) {
            UpmpBTradeAreaInfo tradeareainfo = tradeAreaInfoService.findOneByCode(entity.getMchntArea(), BusinessContainer.data_sta_01, entity.getInstId());
            if (null != tradeareainfo) {
                result.put("tradeAreaName", tradeareainfo.getTradeAreaName());
            }
        }
        //代理机构
        if (StringUtils.isNotBlank(entity.getAgentMchntNo())) {
            UpmpBAgentInfo agentinfo = agentInfoService.findOneByCode(entity.getAgentMchntNo(), BusinessContainer.data_sta_01, entity.getInstId());
            if (null != agentinfo) {
                result.put("agentName", agentinfo.getAgentName());
            }
        }
        //商户等级
        if (StringUtils.isNotBlank(entity.getMchntLevel())) {
            UpmpBMchntLevelInfo mchntlevelinfo = mchntLevelInfoService.findOneByCode(entity.getMchntLevel(), BusinessContainer.data_sta_01, entity.getInstId());
            if (null != mchntlevelinfo) {
                result.put("mchntLevelName", mchntlevelinfo.getMchntLevelName());
            }
        }

        RegionInfoQueryRequest place = new RegionInfoQueryRequest();
        place.setPageIndex(-1);//联机页码从0开始，select2页码从1开始
        place.setPageSize(-1);
        place.setUserId(user.getId());
        //查询省
        if (Common.isNotBlank(entity.getMchntBizProvince())) {
            place.setRegionLevel("01");
            place.setRegionName(entity.getMchntBizProvince());
            try {
                RegionInfoQueryResponse QueryProvinceName = registerListQuery(entity.getInstId(), user, place, bompPublicQueryService, genMerOrder(user.getInstId()));
                result.put("registerProvinceName", QueryProvinceName.getRegionInfoList().get(0).getRegionName());
            } catch (Exception e) {
                log.info(e.getMessage());
            }
        }
        //查询市
        if (Common.isNotBlank(entity.getMchntBizCity())) {
            place.setSuperRegionCode(entity.getMchntBizProvince());
            place.setRegionLevel("02");
            place.setRegionName(entity.getMchntBizCity());
            try {
                RegionInfoQueryResponse QueryBizCityName = registerListQuery(entity.getInstId(), user, place, bompPublicQueryService, genMerOrder(user.getInstId()));
                result.put("registerCityName", QueryBizCityName.getRegionInfoList().get(0).getRegionName());
            } catch (Exception e) {
                log.info(e.getMessage());
            }
        }
        //查询市
        if (Common.isNotBlank(entity.getMchntBizRegion())) {
            place.setSuperRegionCode(entity.getMchntBizCity());
            place.setRegionLevel("03");
            place.setRegionName(entity.getMchntBizRegion());
            try {
                RegionInfoQueryResponse QueryRegionName = registerListQuery(entity.getInstId(), user, place, bompPublicQueryService, genMerOrder(user.getInstId()));
                result.put("registerAreaName", QueryRegionName.getRegionInfoList().get(0).getRegionName());
            } catch (Exception e) {
                log.info(e.getMessage());
            }
        }

        UpmpOrganization organization = organizationService.findOneByCode(entity.getSignInstId(), BusinessContainer.data_sta_01, entity.getInstId());
        if (null != organization) {
            result.put("orgName", organization.getOrgName());
        }*/
        entity.setMchntExpandChannel(BusinessContainer.MCMP_CHANL_ID);
        entity.setCreateTime(DateUtils.formatDate(new Date(), DateUtils.DEFAULT_TIME_FORMAT + ".SSS"));
//        List<LabelValueBean> yesOrNo = Lists.newArrayList();
//        yesOrNo.add(new LabelValueBean("是", IgasYesOrNoEnum.Yes.getType()));
//        yesOrNo.add(new LabelValueBean("否", IgasYesOrNoEnum.No.getType()));
//        result.put("yesOrNo", yesOrNo);
        if (Common.isNotBlank(entity.getCertExpiryDate())) {
            if (entity.getCertExpiryDate().equals("20991231") || entity.getCertExpiryDate().equals("99991231")) {
                entity.setCertExpiryDate("长期");
            }
        }
        result.put("entity", entity);
        return result;
    }


    public MchntBaseInfoQueryResponse mchntBaseInfoQuery(String instId, UpmpUserInfoVO user, String traceNo, String mchntNo, String mchntName, BompQueryTypeEnum queryType, BompMchntQueryService bompQueryService) throws RedpException {
        MchntBaseInfoQueryRequest req = new MchntBaseInfoQueryRequest();
        req.setHeader(CommonUtils.packageBompHeader(traceNo, BompTxnNumEnum.mchntBaseInfoQuery.getType(), instId, queryType.getType()));
        req.setUserId(user.getId());
        req.setMchntNo(mchntNo);
        req.setMchntName(mchntName);

        try {
            log.info("法人行[" + instId + "],用户标识[" + req.getUserId() + "],商户号[" + req.getMchntNo() + "]" + BompTxnNumEnum.mchntBaseInfoQuery.getDesc() + "交易请求报文：" + JSON.toJSONString(req));

            Result<MchntBaseInfoQueryResponse> response = bompQueryService.mchntBaseInfoQuery(req);
            log.info("法人行[" + instId + "],用户标识[" + req.getUserId() + "],商户号[" + req.getMchntNo() + "]" + BompTxnNumEnum.mchntBaseInfoQuery.getDesc() + "交易返回报文：" + JSON.toJSONString(response));
            if (response.isSuccess()) {
                MchntBaseInfoQueryResponse resp = response.getResult();
                // 返回码：00000000-进件成功，其他均视为失败
                if (BusinessContainer.BSPS_SUCCESS.equals(resp.getRespCode())) {
                    log.info("法人行[" + instId + "],用户标识[" + req.getUserId() + "],商户号[" + req.getMchntNo() + "]" + BompTxnNumEnum.mchntBaseInfoQuery.getDesc() + "交易成功");
                    return resp;
                } else {
                    log.error("法人行[" + instId + "],用户标识[" + req.getUserId() + "],商户号[" + req.getMchntNo() + "]" + BompTxnNumEnum.mchntBaseInfoQuery.getDesc() + "交易失败");
                    return null;
                }
            } else {
                log.error("法人行[" + instId + "],用户标识[" + req.getUserId() + "],商户号[" + req.getMchntNo() + "]" + BompTxnNumEnum.mchntBaseInfoQuery.getDesc() + "交易没有获得返回信息");
                return null;
            }
        } catch (Exception e) {
            // TODO: handle exception
            log.error("法人行[" + instId + "],用户标识[" + req.getUserId() + "],商户号[" + req.getMchntNo() + "]" + BompTxnNumEnum.mchntBaseInfoQuery.getDesc() + "交易出现异常，异常信息：" + e.getMessage(), e);
            throw new RedpException("法人行[" + instId + "],用户标识[" + req.getUserId() + "],商户号[" + req.getMchntNo() + "]" + BompTxnNumEnum.mchntBaseInfoQuery.getDesc() + "交易出现异常，异常信息：" + e.getMessage());
        }
    }

    public MchntInfoListQueryResponse mchntInfoListQuery(String instId, UpmpUserInfoVO user, MchntInfoListQueryRequest req, String traceNo) throws RedpException {
        req.setHeader(CommonUtils.packageBompHeader(traceNo, BompTxnNumEnum.mchntInfoListQuery.getType(), instId, null));
        req.setUserId(user.getId());

        try {
            log.info("法人行[" + instId + "],用户标识[" + req.getUserId() + "],商户号[" + req.getMchntNo() + "]" + BompTxnNumEnum.mchntInfoListQuery.getDesc() + "交易请求报文：" + JSON.toJSONString(req));

            Result<MchntInfoListQueryResponse> response = bompMchntQueryService.mchntInfoListQuery(req);
            log.info("法人行[" + instId + "],用户标识[" + req.getUserId() + "],商户号[" + req.getMchntNo() + "]" + BompTxnNumEnum.mchntInfoListQuery.getDesc() + "交易返回报文：" + JSON.toJSONString(response));
            if (response.isSuccess()) {
                MchntInfoListQueryResponse resp = response.getResult();
                // 返回码：00000000-成功，其他均视为失败
                if (BusinessContainer.BSPS_SUCCESS.equals(resp.getRespCode())) {
                    log.info("法人行[" + instId + "],用户标识[" + req.getUserId() + "],商户号[" + req.getMchntNo() + "]" + BompTxnNumEnum.mchntInfoListQuery.getDesc() + "交易成功");
                    return resp;
                } else {
                    log.error("法人行[" + instId + "],用户标识[" + req.getUserId() + "],商户号[" + req.getMchntNo() + "]" + BompTxnNumEnum.mchntInfoListQuery.getDesc() + "交易失败");
                    return null;
                }
            } else {
                log.error("法人行[" + instId + "],用户标识[" + req.getUserId() + "],商户号[" + req.getMchntNo() + "]" + BompTxnNumEnum.mchntInfoListQuery.getDesc() + "交易没有获得返回信息");
                return null;
            }
        } catch (Exception e) {
            // TODO: handle exception
            log.error("法人行[" + instId + "],用户标识[" + req.getUserId() + "],商户号[" + req.getMchntNo() + "]" + BompTxnNumEnum.mchntInfoListQuery.getDesc() + "交易出现异常，异常信息：" + e.getMessage(), e);
            throw new RedpException("法人行[" + instId + "],用户标识[" + req.getUserId() + "],商户号[" + req.getMchntNo() + "]" + BompTxnNumEnum.mchntInfoListQuery.getDesc() + "交易出现异常");
        }
    }

    public MchntLevelListQueryResponse mchntLevelListQuery(String instId, UpmpUserInfoVO user, MchntLevelListQueryRequest req, BompMchntQueryService bompQueryService, String traceNo) throws RedpException {

        req.setHeader(CommonUtils.packageBompHeader(traceNo, BompTxnNumEnum.mchntLevelListQuery.getType(), instId, null));
        req.setUserId(user.getId());

        try {
            log.info("法人行[" + user.getInstId() + "],用户标识[" + req.getUserId() + "]" + BompTxnNumEnum.mchntLevelListQuery.getDesc() + "交易请求报文：" + JSON.toJSONString(req));

            Result<MchntLevelListQueryResponse> response = bompQueryService.mchntLevelListQuery(req);
            log.info("法人行[" + user.getInstId() + "],用户标识[" + req.getUserId() + "]" + BompTxnNumEnum.mchntLevelListQuery.getDesc() + "交易返回报文：" + JSON.toJSONString(response));
            if (response.isSuccess()) {
                MchntLevelListQueryResponse resp = response.getResult();
                // 返回码：00000000-进件成功，其他均视为失败
                if (BusinessContainer.BSPS_SUCCESS.equals(resp.getRespCode())) {
                    log.info("法人行[" + user.getInstId() + "],用户标识[" + req.getUserId() + "]" + BompTxnNumEnum.mchntLevelListQuery.getDesc() + "交易成功");
                    return resp;
                } else {
                    log.error("法人行[" + user.getInstId() + "],用户标识[" + req.getUserId() + "]" + BompTxnNumEnum.mchntLevelListQuery.getDesc() + "交易失败");
                    return null;
                }
            } else {
                log.error("法人行[" + user.getInstId() + "],用户标识[" + req.getUserId() + "]" + BompTxnNumEnum.mchntLevelListQuery.getDesc() + "交易没有获得返回信息");
                return null;
            }
        } catch (Exception e) {
            // TODO: handle exception
            log.error("法人行[" + user.getInstId() + "],用户标识[" + req.getUserId() + "]" + BompTxnNumEnum.mchntLevelListQuery.getDesc() + "交易出现异常，异常信息：" + e.getMessage(), e);
            throw new RedpException("法人行[" + user.getInstId() + "],用户标识[" + req.getUserId() + "]" + BompTxnNumEnum.mchntLevelListQuery.getDesc() + "交易出现异常，异常信息：" + e.getMessage());
        }
    }

    public IndustryInfoQueryResponse industryInfoQuery(String instId, UpmpUserInfoVO user, IndustryInfoQueryRequest
            req, BompPublicQueryService bompQueryService, String traceNo) throws RedpException {
        req.setHeader(CommonUtils.packageBompHeader(traceNo, BompTxnNumEnum.industryInfoQuery.getType(), instId, null));
        req.setUserId(user.getId());

        try {
            log.info("法人行[" + user.getInstId() + "],用户标识[" + req.getUserId() + "]" + BompTxnNumEnum.industryInfoQuery.getDesc() + "交易请求报文：" + JSON.toJSONString(req));

            Result<IndustryInfoQueryResponse> response = bompQueryService.industryInfoQuery(req);
            log.info("法人行[" + user.getInstId() + "],用户标识[" + req.getUserId() + "]" + BompTxnNumEnum.industryInfoQuery.getDesc() + "交易返回报文：" + JSON.toJSONString(response));
            if (response.isSuccess()) {
                IndustryInfoQueryResponse resp = response.getResult();
                // 返回码：00000000-进件成功，其他均视为失败
                if (BusinessContainer.BSPS_SUCCESS.equals(resp.getRespCode())) {
                    log.info("法人行[" + user.getInstId() + "],用户标识[" + req.getUserId() + "]" + BompTxnNumEnum.industryInfoQuery.getDesc() + "交易成功");
                    return resp;
                } else {
                    log.error("法人行[" + user.getInstId() + "],用户标识[" + req.getUserId() + "]" + BompTxnNumEnum.industryInfoQuery.getDesc() + "交易失败");
                    return null;
                }
            } else {
                log.error("法人行[" + user.getInstId() + "],用户标识[" + req.getUserId() + "]" + BompTxnNumEnum.industryInfoQuery.getDesc() + "交易没有获得返回信息");
                return null;
            }
        } catch (Exception e) {
            // TODO: handle exception
            log.error("法人行[" + user.getInstId() + "],用户标识[" + req.getUserId() + "]" + BompTxnNumEnum.industryInfoQuery.getDesc() + "交易出现异常，异常信息：" + e.getMessage(), e);
            throw new RedpException("法人行[" + user.getInstId() + "],用户标识[" + req.getUserId() + "]" + BompTxnNumEnum.industryInfoQuery.getDesc() + "交易出现异常，异常信息：" + e.getMessage());
        }
    }

    public AgentMchntListQueryResponse agentMchntListQuery(String instId, UpmpUserInfoVO user, AgentMchntListQueryRequest req, BompMchntQueryService bompQueryService, String traceNo) throws RedpException {

        req.setHeader(CommonUtils.packageBompHeader(traceNo, BompTxnNumEnum.agentMchntListQuery.getType(), instId, null));
        req.setUserId(user.getId());

        try {
            log.info("法人行[" + user.getInstId() + "],用户标识[" + req.getUserId() + "]" + BompTxnNumEnum.agentMchntListQuery.getDesc() + "交易请求报文：" + JSON.toJSONString(req));

            Result<AgentMchntListQueryResponse> response = bompQueryService.agentMchntListQuery(req);
            log.info("法人行[" + user.getInstId() + "],用户标识[" + req.getUserId() + "]" + BompTxnNumEnum.agentMchntListQuery.getDesc() + "交易返回报文：" + JSON.toJSONString(response));
            if (response.isSuccess()) {
                AgentMchntListQueryResponse resp = response.getResult();
                // 返回码：00000000-进件成功，其他均视为失败
                if (BusinessContainer.BSPS_SUCCESS.equals(resp.getRespCode())) {
                    log.info("法人行[" + user.getInstId() + "],用户标识[" + req.getUserId() + "]" + BompTxnNumEnum.agentMchntListQuery.getDesc() + "交易成功");
                    return resp;
                } else {
                    log.error("法人行[" + user.getInstId() + "],用户标识[" + req.getUserId() + "]" + BompTxnNumEnum.agentMchntListQuery.getDesc() + "交易失败");
                    return null;
                }
            } else {
                log.error("法人行[" + user.getInstId() + "],用户标识[" + req.getUserId() + "]" + BompTxnNumEnum.agentMchntListQuery.getDesc() + "交易没有获得返回信息");
                return null;
            }
        } catch (Exception e) {
            // TODO: handle exception
            log.error("法人行[" + user.getInstId() + "],用户标识[" + req.getUserId() + "]" + BompTxnNumEnum.agentMchntListQuery.getDesc() + "交易出现异常，异常信息：" + e.getMessage(), e);
            throw new RedpException("法人行[" + user.getInstId() + "],用户标识[" + req.getUserId() + "]" + BompTxnNumEnum.agentMchntListQuery.getDesc() + "交易出现异常，异常信息：" + e.getMessage());
        }
    }

    public PlatMchntListQueryResponse platMchntListQuery(String instId, UpmpUserInfoVO user, PlatMchntListQueryRequest req, BompMchntQueryService bompQueryService, String traceNo) throws RedpException {

        req.setHeader(CommonUtils.packageBompHeader(traceNo, BompTxnNumEnum.platMchntListQuery.getType(), instId, null));
        req.setUserId(user.getId());

        try {
            log.info("法人行[" + user.getInstId() + "],用户标识[" + req.getUserId() + "]" + BompTxnNumEnum.platMchntListQuery.getDesc() + "交易请求报文：" + JSON.toJSONString(req));

            Result<PlatMchntListQueryResponse> response = bompQueryService.platMchntListQuery(req);
            log.info("法人行[" + user.getInstId() + "],用户标识[" + req.getUserId() + "]" + BompTxnNumEnum.platMchntListQuery.getDesc() + "交易返回报文：" + JSON.toJSONString(response));
            if (response.isSuccess()) {
                PlatMchntListQueryResponse resp = response.getResult();
                // 返回码：00000000-进件成功，其他均视为失败
                if (BusinessContainer.BSPS_SUCCESS.equals(resp.getRespCode())) {
                    log.info("法人行[" + user.getInstId() + "],用户标识[" + req.getUserId() + "]" + BompTxnNumEnum.platMchntListQuery.getDesc() + "交易成功");
                    return resp;
                } else {
                    log.error("法人行[" + user.getInstId() + "],用户标识[" + req.getUserId() + "]" + BompTxnNumEnum.platMchntListQuery.getDesc() + "交易失败");
                    return null;
                }
            } else {
                log.error("法人行[" + user.getInstId() + "],用户标识[" + req.getUserId() + "]" + BompTxnNumEnum.platMchntListQuery.getDesc() + "交易没有获得返回信息");
                return null;
            }
        } catch (Exception e) {
            // TODO: handle exception
            log.error("法人行[" + user.getInstId() + "],用户标识[" + req.getUserId() + "]" + BompTxnNumEnum.platMchntListQuery.getDesc() + "交易出现异常，异常信息：" + e.getMessage(), e);
            throw new RedpException("法人行[" + user.getInstId() + "],用户标识[" + req.getUserId() + "]" + BompTxnNumEnum.platMchntListQuery.getDesc() + "交易出现异常，异常信息：" + e.getMessage());
        }
    }

    public GroupMchntListQueryResponse groupMchntListQuery(String instId, UpmpUserInfoVO user, GroupMchntListQueryRequest req, BompMchntQueryService bompQueryService, String traceNo) throws RedpException {

        req.setHeader(CommonUtils.packageBompHeader(traceNo, BompTxnNumEnum.groupMchntListQuery.getType(), instId, null));
        req.setUserId(user.getId());

        try {
            log.info("法人行[" + user.getInstId() + "],用户标识[" + req.getUserId() + "]" + BompTxnNumEnum.groupMchntListQuery.getDesc() + "交易请求报文：" + JSON.toJSONString(req));

            Result<GroupMchntListQueryResponse> response = bompQueryService.groupMchntListQuery(req);
            log.info("法人行[" + user.getInstId() + "],用户标识[" + req.getUserId() + "]" + BompTxnNumEnum.groupMchntListQuery.getDesc() + "交易返回报文：" + JSON.toJSONString(response));
            if (response.isSuccess()) {
                GroupMchntListQueryResponse resp = response.getResult();
                // 返回码：00000000-进件成功，其他均视为失败
                if (BusinessContainer.BSPS_SUCCESS.equals(resp.getRespCode())) {
                    log.info("法人行[" + user.getInstId() + "],用户标识[" + req.getUserId() + "]" + BompTxnNumEnum.groupMchntListQuery.getDesc() + "交易成功");
                    return resp;
                } else {
                    log.error("法人行[" + user.getInstId() + "],用户标识[" + req.getUserId() + "]" + BompTxnNumEnum.groupMchntListQuery.getDesc() + "交易失败");
                    return null;
                }
            } else {
                log.error("法人行[" + user.getInstId() + "],用户标识[" + req.getUserId() + "]" + BompTxnNumEnum.groupMchntListQuery.getDesc() + "交易没有获得返回信息");
                return null;
            }
        } catch (Exception e) {
            // TODO: handle exception
            log.error("法人行[" + user.getInstId() + "],用户标识[" + req.getUserId() + "]" + BompTxnNumEnum.groupMchntListQuery.getDesc() + "交易出现异常，异常信息：" + e.getMessage(), e);
            throw new RedpException("法人行[" + user.getInstId() + "],用户标识[" + req.getUserId() + "]" + BompTxnNumEnum.groupMchntListQuery.getDesc() + "交易出现异常，异常信息：" + e.getMessage());
        }
    }

    public MchntAreaListQueryResponse mchntAreaListQuery(String instId, UpmpUserInfoVO user, MchntAreaListQueryRequest req, BompMchntQueryService bompQueryService, String traceNo) throws RedpException {
        req.setHeader(CommonUtils.packageBompHeader(traceNo, BompTxnNumEnum.mchntAreaListQuery.getType(), instId, null));
        req.setUserId(user.getId());

        try {
            log.info("法人行[" + user.getInstId() + "],用户标识[" + req.getUserId() + "]" + BompTxnNumEnum.mchntAreaListQuery.getDesc() + "交易请求报文：" + JSON.toJSONString(req));

            Result<MchntAreaListQueryResponse> response = bompQueryService.mchntAreaListQuery(req);
            log.info("法人行[" + user.getInstId() + "],用户标识[" + req.getUserId() + "]" + BompTxnNumEnum.mchntAreaListQuery.getDesc() + "交易返回报文：" + JSON.toJSONString(response));
            if (response.isSuccess()) {
                MchntAreaListQueryResponse resp = response.getResult();
                // 返回码：00000000-进件成功，其他均视为失败
                if (BusinessContainer.BSPS_SUCCESS.equals(resp.getRespCode())) {
                    log.info("法人行[" + user.getInstId() + "],用户标识[" + req.getUserId() + "]" + BompTxnNumEnum.mchntAreaListQuery.getDesc() + "交易成功");
                    return resp;
                } else {
                    log.error("法人行[" + user.getInstId() + "],用户标识[" + req.getUserId() + "]" + BompTxnNumEnum.mchntAreaListQuery.getDesc() + "交易失败");
                    return null;
                }
            } else {
                log.error("法人行[" + user.getInstId() + "],用户标识[" + req.getUserId() + "]" + BompTxnNumEnum.mchntAreaListQuery.getDesc() + "交易没有获得返回信息");
                return null;
            }
        } catch (Exception e) {
            // TODO: handle exception
            log.error("法人行[" + user.getInstId() + "],用户标识[" + req.getUserId() + "]" + BompTxnNumEnum.mchntAreaListQuery.getDesc() + "交易出现异常，异常信息：" + e.getMessage(), e);
            throw new RedpException("法人行[" + user.getInstId() + "],用户标识[" + req.getUserId() + "]" + BompTxnNumEnum.mchntAreaListQuery.getDesc() + "交易出现异常，异常信息：" + e.getMessage());
        }
    }

    public FeeTemplateListQueryResponse feeTemplateListQuery(String instId, UpmpUserInfoVO user, FeeTemplateListQueryRequest req, BompPublicQueryService bompQueryService, String traceNo) throws RedpException {
        req.setHeader(CommonUtils.packageBompHeader(traceNo, BompTxnNumEnum.feeTemplateListQuery.getType(), instId, null));
        req.setUserId(user.getId());

        try {
            log.info("法人行[" + user.getInstId() + "],用户标识[" + req.getUserId() + "]" + BompTxnNumEnum.feeTemplateListQuery.getDesc() + "交易请求报文：" + JSON.toJSONString(req));

            Result<FeeTemplateListQueryResponse> response = bompQueryService.feeTemplateListQuery(req);
            log.info("法人行[" + user.getInstId() + "],用户标识[" + req.getUserId() + "]" + BompTxnNumEnum.feeTemplateListQuery.getDesc() + "交易返回报文：" + JSON.toJSONString(response));
            if (response.isSuccess()) {
                FeeTemplateListQueryResponse resp = response.getResult();
                // 返回码：00000000-进件成功，其他均视为失败
                if (BusinessContainer.BSPS_SUCCESS.equals(resp.getRespCode())) {
                    log.info("法人行[" + user.getInstId() + "],用户标识[" + req.getUserId() + "]" + BompTxnNumEnum.feeTemplateListQuery.getDesc() + "交易成功");
                    return resp;
                } else {
                    log.error("法人行[" + user.getInstId() + "],用户标识[" + req.getUserId() + "]" + BompTxnNumEnum.feeTemplateListQuery.getDesc() + "交易失败");
                    return null;
                }
            } else {
                log.error("法人行[" + user.getInstId() + "],用户标识[" + req.getUserId() + "]" + BompTxnNumEnum.feeTemplateListQuery.getDesc() + "交易没有获得返回信息");
                return null;
            }
        } catch (Exception e) {
            // TODO: handle exception
            log.error("法人行[" + user.getInstId() + "],用户标识[" + req.getUserId() + "]" + BompTxnNumEnum.feeTemplateListQuery.getDesc() + "交易出现异常，异常信息：" + e.getMessage(), e);
            throw new RedpException("法人行[" + user.getInstId() + "],用户标识[" + req.getUserId() + "]" + BompTxnNumEnum.feeTemplateListQuery.getDesc() + "交易出现异常，异常信息：" + e.getMessage());
        }
    }

    public RegionInfoQueryResponse registerListQuery(String instId, UpmpUserInfoVO user, RegionInfoQueryRequest req, BompPublicQueryService bompQueryService, String traceNo) throws RedpException {

        req.setHeader(CommonUtils.packageBompHeader(traceNo, BompTxnNumEnum.regionInfoQuery.getType(), instId, null));
        req.setUserId(user.getId());

        try {
            log.info("法人行[" + user.getInstId() + "],用户标识[" + req.getUserId() + "]" + BompTxnNumEnum.regionInfoQuery.getDesc() + "交易请求报文：" + JSON.toJSONString(req));

            Result<RegionInfoQueryResponse> response = bompQueryService.regionInfoQuery(req);
            log.info("法人行[" + user.getInstId() + "],用户标识[" + req.getUserId() + "]" + BompTxnNumEnum.regionInfoQuery.getDesc() + "交易返回报文：" + JSON.toJSONString(response));
            if (response.isSuccess()) {
                RegionInfoQueryResponse resp = response.getResult();
                // 返回码：00000000-进件成功，其他均视为失败
                if (BusinessContainer.BSPS_SUCCESS.equals(resp.getRespCode())) {
                    log.info("法人行[" + user.getInstId() + "],用户标识[" + req.getUserId() + "]" + BompTxnNumEnum.regionInfoQuery.getDesc() + "交易成功");
                    return resp;
                } else {
                    log.error("法人行[" + user.getInstId() + "],用户标识[" + req.getUserId() + "]" + BompTxnNumEnum.regionInfoQuery.getDesc() + "交易失败");
                    return null;
                }
            } else {
                log.error("法人行[" + user.getInstId() + "],用户标识[" + req.getUserId() + "]" + BompTxnNumEnum.regionInfoQuery.getDesc() + "交易没有获得返回信息");
                return null;
            }
        } catch (Exception e) {
            // TODO: handle exception
            log.error("法人行[" + user.getInstId() + "],用户标识[" + req.getUserId() + "]" + BompTxnNumEnum.regionInfoQuery.getDesc() + "交易出现异常，异常信息：" + e.getMessage(), e);
            throw new RedpException("法人行[" + user.getInstId() + "],用户标识[" + req.getUserId() + "]" + BompTxnNumEnum.regionInfoQuery.getDesc() + "交易出现异常，异常信息：" + e.getMessage());
        }
    }

    /**
     * 查询商户等级名称
     *
     * @param instId
     * @param user
     * @param mchntLevel       等级编码
     * @param bompQueryService
     * @param traceNo
     * @return
     * @throws RedpException
     */
    public String getMchntLevelName(String instId, UpmpUserInfoVO user, String mchntLevel, BompMchntQueryService bompQueryService, String traceNo) throws RedpException {
        MchntLevelInfoBean bean = getMchntLevelInfo(instId, user, mchntLevel, "", bompQueryService, traceNo);
        if (Common.isNotBlank(bean)) {
            return bean.getMchntLevelName();
        }
        return "";
    }

    public MchntLevelInfoBean getMchntLevelInfo(String instId, UpmpUserInfoVO user, String mchntLevel, String mchnLevelName, BompMchntQueryService bompQueryService, String traceNo) throws RedpException {
        MchntLevelListQueryRequest req = new MchntLevelListQueryRequest();
        req.setPageIndex(0);//联机页码从0开始
        req.setPageSize(Integer.valueOf(BusinessContainer.ECP_PAGE_DEFAULTROWS));
        req.setMchntLevel(mchntLevel);
        req.setMchntLevelName(mchnLevelName);
        req.setUserId(user.getId());

        MchntLevelListQueryResponse resp = mchntLevelListQuery(instId, user, req, bompQueryService, traceNo);
        if (Common.isNotBlank(resp)) {
            List<MchntLevelInfoBean> list = Lists.newArrayList();
            if (Common.isNotBlank(resp) && CollectionUtils.isNotEmpty(resp.getMchntLevelInfoList())) {
                list = resp.getMchntLevelInfoList();
            }
            if (CollectionUtils.isNotEmpty(list)) {
                return list.get(0);
            }
        }
        return null;
    }

    /**
     * 查询行业类别名称
     *
     * @param instId
     * @param user
     * @param code
     * @param bompQueryService
     * @param traceNo
     * @return
     * @throws RedpException
     */
    public String getIndustryTypeCname(String instId, UpmpUserInfoVO user, String code, BompPublicQueryService bompQueryService, String traceNo) throws RedpException {
        IndustryInfoBean bean = getIndustryType(instId, user, code, bompQueryService, traceNo);
        if (Common.isNotBlank(bean)) {
            return bean.getIndustryName();
        }
        return "";
    }

    public IndustryInfoBean getIndustryType(String instId, UpmpUserInfoVO user, String code, BompPublicQueryService bompQueryService, String traceNo) throws RedpException {
        IndustryInfoQueryRequest req = new IndustryInfoQueryRequest();
        req.setManagementScope(code);
        req.setPageIndex(0);//联机页码从0开始
        req.setPageSize(Integer.valueOf(BusinessContainer.ECP_PAGE_DEFAULTROWS));
        req.setIndustryCode(code);
        req.setUserId(user.getId());

        IndustryInfoQueryResponse resp = industryInfoQuery(instId, user, req, bompQueryService, traceNo);
        if (Common.isNotBlank(resp)) {
            List<IndustryInfoBean> list = Lists.newArrayList();
            if (Common.isNotBlank(resp) && CollectionUtils.isNotEmpty(resp.getIndustrylInfoList())) {
                list = resp.getIndustrylInfoList();
            }
            if (CollectionUtils.isNotEmpty(list)) {
                return list.get(0);
            }
        }
        return null;
    }

    /**
     * 查询代理机构名称
     *
     * @param instId
     * @param user
     * @param mchntNo          代理机构编码
     * @param bompQueryService
     * @param traceNo
     * @return
     * @throws RedpException
     */
    public String getAgentMchntName(String instId, UpmpUserInfoVO user, String mchntNo, BompMchntQueryService bompQueryService, String traceNo) throws RedpException {
        AgentMchntInfoBean bean = getAgentMchntInfo(instId, user, mchntNo, "", bompQueryService, traceNo);
        if (Common.isNotBlank(bean)) {
            return bean.getAgentMchntName();
        }
        return "";
    }

    public AgentMchntInfoBean getAgentMchntInfo(String instId, UpmpUserInfoVO user, String mchntNo, String mchntName, BompMchntQueryService bompQueryService, String traceNo) throws RedpException {
        AgentMchntListQueryRequest req = new AgentMchntListQueryRequest();
        req.setPageIndex(0);//联机页码从0开始
        req.setPageSize(Integer.valueOf(BusinessContainer.ECP_PAGE_DEFAULTROWS));
        req.setAgentMchntNo(mchntNo);
        req.setAgentMchntName(mchntName);
        req.setUserId(user.getId());

        AgentMchntListQueryResponse resp = agentMchntListQuery(instId, user, req, bompQueryService, traceNo);
        if (Common.isNotBlank(resp)) {
            List<AgentMchntInfoBean> list = Lists.newArrayList();
            if (Common.isNotBlank(resp) && CollectionUtils.isNotEmpty(resp.getAgentMchntInfoList())) {
                list = resp.getAgentMchntInfoList();
            }
            if (CollectionUtils.isNotEmpty(list)) {
                return list.get(0);
            }
        }
        return null;
    }

    /**
     * 查询商圈名称
     *
     * @param instId
     * @param user
     * @param mchntArea        商圈编码
     * @param bompQueryService
     * @param traceNo
     * @return
     * @throws RedpException
     */
    public String getMchntAreaName(String instId, UpmpUserInfoVO user, String mchntArea, BompMchntQueryService bompQueryService, String traceNo) throws RedpException {
        MchntAreaInfoBean bean = getMchntAreaInfo(instId, user, mchntArea, "", bompQueryService, traceNo);
        if (Common.isNotBlank(bean)) {
            return bean.getMchntAreaName();
        }
        return "";
    }

    public MchntAreaInfoBean getMchntAreaInfo(String instId, UpmpUserInfoVO user, String mchntArea, String mchntAreaName, BompMchntQueryService bompQueryService, String traceNo) throws RedpException {
        MchntAreaListQueryRequest req = new MchntAreaListQueryRequest();
        req.setPageIndex(0);//联机页码从0开始
        req.setPageSize(Integer.valueOf(BusinessContainer.ECP_PAGE_DEFAULTROWS));
        req.setMchntArea(mchntArea);
        req.setMchntAreaName(mchntAreaName);
        req.setUserId(user.getId());

        MchntAreaListQueryResponse resp = mchntAreaListQuery(instId, user, req, bompQueryService, traceNo);
        if (Common.isNotBlank(resp)) {
            List<MchntAreaInfoBean> list = Lists.newArrayList();
            if (Common.isNotBlank(resp) && CollectionUtils.isNotEmpty(resp.getMchntAreaInfoList())) {
                list = resp.getMchntAreaInfoList();
            }
            if (CollectionUtils.isNotEmpty(list)) {
                return list.get(0);
            }
        }
        return null;
    }

    /**
     * 查询集团商户名称
     *
     * @param instId
     * @param user
     * @param mchntNo
     * @param bompQueryService
     * @param traceNo
     * @return
     * @throws RedpException
     */
    public String getGroupMchntName(String instId, UpmpUserInfoVO user, String mchntNo, BompMchntQueryService bompQueryService, String traceNo) throws RedpException {
        GroupMchntInfoBean bean = getGroupMchntInfo(instId, user, mchntNo, "", bompQueryService, traceNo);
        if (Common.isNotBlank(bean)) {
            return bean.getGroupMchntName();
        }
        return "";
    }

    public GroupMchntInfoBean getGroupMchntInfo(String instId, UpmpUserInfoVO user, String mchntNo, String mchntName, BompMchntQueryService bompQueryService, String traceNo) throws RedpException {
        GroupMchntListQueryRequest req = new GroupMchntListQueryRequest();
        req.setPageIndex(0);//联机页码从0开始
        req.setPageSize(Integer.valueOf(BusinessContainer.ECP_PAGE_DEFAULTROWS));
        req.setGroupMchntNo(mchntNo);
        req.setGroupMchntName(mchntName);
        req.setUserId(user.getId());

        GroupMchntListQueryResponse resp = groupMchntListQuery(instId, user, req, bompQueryService, traceNo);
        if (Common.isNotBlank(resp)) {
            List<GroupMchntInfoBean> list = Lists.newArrayList();
            if (Common.isNotBlank(resp) && CollectionUtils.isNotEmpty(resp.getGroupMchntInfoList())) {
                list = resp.getGroupMchntInfoList();
            }
            if (CollectionUtils.isNotEmpty(list)) {
                return list.get(0);
            }
        }
        return null;
    }

    /**
     * 查询平台商户名称
     *
     * @param instId
     * @param user
     * @param mchntNo          平台商户号
     * @param bompQueryService
     * @param traceNo
     * @return
     * @throws RedpException
     */
    public String getPlatMchntName(String instId, UpmpUserInfoVO user, String mchntNo, BompMchntQueryService bompQueryService, String traceNo) throws RedpException {
        PlatMchntInfoBean bean = getPlatMchntInfo(instId, user, mchntNo, "", bompQueryService, traceNo);
        if (Common.isNotBlank(bean)) {
            return bean.getPlatMchntName();
        }
        return "";
    }

    public PlatMchntInfoBean getPlatMchntInfo(String instId, UpmpUserInfoVO user, String mchntNo, String mchntName, BompMchntQueryService bompQueryService, String traceNo) throws RedpException {
        PlatMchntListQueryRequest req = new PlatMchntListQueryRequest();
        req.setPageIndex(0);//联机页码从0开始
        req.setPageSize(Integer.valueOf(BusinessContainer.ECP_PAGE_DEFAULTROWS));
        req.setPlatMchntNo(mchntNo);
        req.setPlatMchntName(mchntName);
        req.setUserId(user.getId());

        PlatMchntListQueryResponse resp = platMchntListQuery(instId, user, req, bompQueryService, traceNo);
        if (Common.isNotBlank(resp)) {

            List<PlatMchntInfoBean> list = Lists.newArrayList();
            if (Common.isNotBlank(resp) && CollectionUtils.isNotEmpty(resp.getPlatMchntInfoList())) {
                list = resp.getPlatMchntInfoList();
            }
            if (CollectionUtils.isNotEmpty(list)) {
                return list.get(0);
            }
        }
        return null;
    }

    /**
     * 查询商户中文名称
     *
     * @param instId
     * @param user
     * @param mchntNo
     * @param queryType
     * @param bompQueryService
     * @param traceNo
     * @return
     * @throws RedpException
     */
    public String getMchntCname(String instId, UpmpUserInfoVO user, String mchntNo, BompQueryTypeEnum queryType, BompMchntQueryService bompQueryService, String traceNo) throws RedpException {
        MchntBaseInfoBean bean = getMchntBaseInfo(instId, user, mchntNo, "", queryType, bompQueryService, traceNo);
        if (Common.isNotBlank(bean)) {
            return bean.getMchntName();
        }
        return "";
    }

    public MchntBaseInfoBean getMchntBaseInfo(String instId, UpmpUserInfoVO user, String mchntNo, String mchntName, BompQueryTypeEnum queryType, BompMchntQueryService bompQueryService, String traceNo) throws RedpException {
        MchntBaseInfoQueryResponse resp = mchntBaseInfoQuery(instId, user, traceNo, mchntNo, mchntName, queryType, bompQueryService);
        if (Common.isNotBlank(resp)) {
            if (Common.isNotBlank(resp) && Common.isNotBlank(resp.getMchntBaseInfo())) {
                return resp.getMchntBaseInfo();
            }
        }
        return null;
    }

    @Override
    public ParamQueryResponse paramQuery(String instId, ParamQueryRequest req, String traceNo) throws RedpException {
        req.setHeader(CommonUtils.packageBompHeader(traceNo, BompTxnNumEnum.paramQuery.getType(), instId, null));

        try {
            log.info("法人行[" + instId + "],用户标识[" + req.getUserId() + "]" + BompTxnNumEnum.paramQuery.getDesc() + "交易请求报文：" + JSON.toJSONString(req));
            Result<ParamQueryResponse> response = bompMchntPublicDealService.paramQuery(req);
            log.info("法人行[" + instId + "],用户标识[" + req.getUserId() + "]" + BompTxnNumEnum.paramQuery.getDesc() + "交易返回报文：" + JSON.toJSONString(response));
            if (response.isSuccess()) {
                ParamQueryResponse resp = response.getResult();
                // 返回码：00000000-进件成功，其他均视为失败
                if (BusinessContainer.BSPS_SUCCESS.equals(resp.getRespCode())) {
                    log.info("法人行[" + instId + "],用户标识[" + req.getUserId() + "]" + BompTxnNumEnum.paramQuery.getDesc() + "交易成功");
                    return resp;
                } else {
                    log.error("法人行[" + instId + "],用户标识[" + req.getUserId() + "]" + BompTxnNumEnum.paramQuery.getDesc() + "交易失败");
                    return null;
                }
            } else {
                log.error("法人行[" + instId + "],用户标识[" + req.getUserId() + "]" + BompTxnNumEnum.paramQuery.getDesc() + "交易没有获得返回信息");
                return null;
            }
        } catch (Exception e) {
            // TODO: handle exception
            log.error("法人行[" + instId + "],用户标识[" + req.getUserId() + "]" + BompTxnNumEnum.paramQuery.getDesc() + "交易出现异常，异常信息：" + e.getMessage(), e);
            throw new RedpException("法人行[" + instId + "],用户标识[" + req.getUserId() + "]" + BompTxnNumEnum.paramQuery.getDesc() + "交易出现异常，异常信息：" + e.getMessage());
        }
    }

    @Override
    public Map<String, Object> editSave(UpmpBMchntBaseInfo entity) throws RedpException {
        UpmpUserInfoVO user = CommonUtils.getCurrentUser(upmpSysParamService);
        CommonUtils.validateUserInst(entity.getInstId(), user);
        if (Common.isNotBlank(entity.getCertExpiryDate())) {
            if (entity.getCertExpiryDate().equals("长期")) {
                entity.setCertExpiryDate("99991231");
            }
        }
        Map<String, Object> result = Maps.newHashMap();
        result.put("mchntType", entity.getMchntType());
        if (PageOptFlagEnum.OPT_FLAG_ADD.getType().equals(entity.getOptFlag())
                || PageOptFlagEnum.OPT_FLAG_UPDATE.getType().equals(entity.getOptFlag())) {
            if (!entity.getMchntType().equals("11")) {
                entity.setIndependentDataFlag("Y");
            }
            MchntBaseInfoManageRequest req = new MchntBaseInfoManageRequest();
            MchntBaseInfoBean mchntBaseInfo = new MchntBaseInfoBean();
            MchntContactsInfoBean mchntContactsInfo = new MchntContactsInfoBean();
            BeanUtils.copyProperties(entity, mchntBaseInfo);
            BeanUtils.copyProperties(entity, mchntContactsInfo);
            mchntContactsInfo.setContactName(entity.getMchntContactName());
            mchntContactsInfo.setContactCertType(entity.getMchntContactCertType());
            mchntContactsInfo.setContactCertNo(entity.getMchntContactCertNo());
            mchntContactsInfo.setContactPhone(entity.getMchntContactPhone());
            mchntContactsInfo.setContactMobile(entity.getMchntContactMobile());
            mchntContactsInfo.setContactEmail(entity.getMchntContactEmail());
            req.setMchntBaseInfoBean(mchntBaseInfo);
            req.setMchntContactsInfoBean(mchntContactsInfo);
            req.setUserId(user.getId());
            if (Common.isBlank(entity.getCashWithdrawalFlag())) {
                entity.setCashWithdrawalFlag(IgasYesOrNoEnum.No.getType());
            }

            //新增操作先查一次看之前是否已经保存，如果已经保存则修改
            if (PageOptFlagEnum.OPT_FLAG_ADD.getType().equals(entity.getOptFlag())) {
                MchntBaseInfoQueryResponse resp = this.mchntBaseInfoQuery(entity.getInstId(), user, genMerOrder(entity.getInstId()), entity.getMchntNo(), null, BompQueryTypeEnum.REAL, bompMchntQueryService);
                if (Common.isNotBlank(resp)) {//如果应答非空则认为是修改
                    entity.setOptFlag(PageOptFlagEnum.OPT_FLAG_UPDATE.getType());
                }
            }
            String traceNo = genMerOrder(entity.getInstId());
            String instId = entity.getInstId();
            String optFlag = entity.getOptFlag();
            /**商户写死必须审核*/
            req.setHeader(CommonUtils.packageBompHeader(traceNo, BompTxnNumEnum.mchntBaseInfoManage.getType(), instId, null));
            if (PageOptFlagEnum.OPT_FLAG_ADD.getType().equals(optFlag)) {
                req.setOprType(BompManageOprTypeEnum.CREATE.getType());
                UpmpPrivilegeCheck privilegeCheck = upmpPrivilegeCheckService.getPrivilegeCheckByPrivilegeCode(entity.getInstId(),
                        oprBtnNamePrefix + BusinessContainer.AUTH_PRIVILEGE_CODE_SPLIT + PageOptFlagEnum.OPT_FLAG_ADD.getDesc());
                if (null != privilegeCheck && BusinessContainer.YES.equals(privilegeCheck.getChecked())) {
                    req.setChecked(BompAuditFlagEnum.CHECK.getType());
                    req.setOprMenuId(oprMenuId);
                    req.setOprMenuName(oprMenuName);
                    req.setWebNextUrl(webNextUrl);
                    //设置主记录是否需要显示
                    req.setMasterShowFlag(IgasYesOrNoEnum.Yes.getType());

                } else {
                /*req.setChecked(BompAuditFlagEnum.NO_CHECK.getType());
                //设置主记录是否需要显示
                req.setMasterShowFlag(IgasYesOrNoEnum.Yes.getType());*/
                    req.setChecked(BompAuditFlagEnum.CHECK.getType());
                    req.setOprMenuId(oprMenuId);
                    req.setOprMenuName(oprMenuName);
                    req.setWebNextUrl(webNextUrl);
                    //设置主记录是否需要显示
                    req.setMasterShowFlag(IgasYesOrNoEnum.Yes.getType());
                }
            } else if (PageOptFlagEnum.OPT_FLAG_UPDATE.getType().equals(optFlag)) {

                req.setOprType(BompManageOprTypeEnum.MODIFY.getType());
                UpmpPrivilegeCheck privilegeCheck = upmpPrivilegeCheckService.getPrivilegeCheckByPrivilegeCode(entity.getInstId(),
                        oprBtnNamePrefix + BusinessContainer.AUTH_PRIVILEGE_CODE_SPLIT + PageOptFlagEnum.OPT_FLAG_UPDATE.getDesc());

                if (null != privilegeCheck && BusinessContainer.YES.equals(privilegeCheck.getChecked())) {
                    req.setChecked(BompAuditFlagEnum.CHECK.getType());
                    req.setOprMenuId(oprMenuId);
                    req.setOprMenuName(oprMenuName);
                    req.setWebNextUrl(webNextUrl);
                    //设置主记录是否需要显示
                    req.setMasterShowFlag(IgasYesOrNoEnum.Yes.getType());

                } else {
                /*req.setChecked(BompAuditFlagEnum.NO_CHECK.getType());
                //设置主记录是否需要显示
                req.setMasterShowFlag(IgasYesOrNoEnum.Yes.getType());*/
                    req.setChecked(BompAuditFlagEnum.CHECK.getType());
                    req.setOprMenuId(oprMenuId);
                    req.setOprMenuName(oprMenuName);
                    req.setWebNextUrl(webNextUrl);
                    //设置主记录是否需要显示
                    req.setMasterShowFlag(IgasYesOrNoEnum.Yes.getType());
                }
            } else {
                throw new RedpException("不支持的操作");
            }

            try {

                log.info("法人行[" + instId + "],用户标识[" + req.getUserId() + "],商户号[" + req.getMchntBaseInfoBean().getMchntNo() + "]" + BompTxnNumEnum.mchntBaseInfoManage.getDesc() + "交易请求报文：" + JSON.toJSONString(req));

                Result<MchntBaseInfoManageResponse> response = bompMchntManageService.mchntBaseInfoManage(req);

                log.info("法人行[" + instId + "],用户标识[" + req.getUserId() + "],商户号[" + req.getMchntBaseInfoBean().getMchntNo() + "]" + BompTxnNumEnum.mchntBaseInfoManage.getDesc() + "交易返回报文：" + JSON.toJSONString(response));
                if (response.isSuccess()) {
                    MchntBaseInfoManageResponse resp = response.getResult();
                    // 返回码：00000000-进件成功，其他均视为失败
                    if (BusinessContainer.BSPS_SUCCESS.equals(resp.getRespCode())) {
                        result.put("respCode", resp.getRespCode());
                        result.put("respMsg", resp.getRespDesc());

                        result.put("instId", instId);
                        result.put("mchntNo", resp.getMchntNo());
                        result.put("optFlag", optFlag);
                        log.info("法人行[" + instId + "],用户标识[" + req.getUserId() + "],商户号[" + req.getMchntBaseInfoBean().getMchntNo() + "]" + BompTxnNumEnum.mchntBaseInfoManage.getDesc() + "交易成功");
                        return result;
                    } else {
                        result.put("respCode", resp.getRespCode());
                        result.put("respMsg", resp.getRespDesc());
                        if (resp.getRespCode().equals(RespCodeEnum.BLACK_LIST_NET_WORD.getRespCode()) || resp.getRespCode().equals(RespCodeEnum.CHAIN_IS_NULL.getRespCode()) || resp.getRespCode().equals(RespCodeEnum.SIGN_INST_IS_NULL.getRespCode()) || resp.getRespCode().equals(RespCodeEnum.PLAT_INST_IS_NULL.getRespCode()) || resp.getRespCode().equals(RespCodeEnum.GROUP_INST_IS_NULL.getRespCode()) || resp.getRespCode().equals(RespCodeEnum.AGENT_INST_IS_NULL.getRespCode())) {
                            return result;
                        }
                        return result;
                    }
                } else {
                    result.put("resCode", BusinessContainer.ERROR);
                    result.put("resMsg", BompTxnNumEnum.mchntBaseInfoManage.getDesc() + "没有获得返回报文");
                    log.error("法人行[" + instId + "],用户标识[" + req.getUserId() + "],商户号[" + req.getMchntBaseInfoBean().getMchntNo() + "]" + BompTxnNumEnum.mchntBaseInfoManage.getDesc() + "交易没有获得返回信息");
                    return result;
                }
            } catch (Exception e) {
                // TODO: handle exception
                result.put("resCode", BusinessContainer.ERROR);
                result.put("resMsg", e.getMessage());
                log.error("法人行[" + instId + "],用户标识[" + req.getUserId() + "],商户号[" + req.getMchntBaseInfoBean().getMchntNo() + "]" + BompTxnNumEnum.mchntBaseInfoManage.getDesc() + "交易出现异常，异常信息：" + e.getMessage(), e);
//            throw new RedpException("商户编号为：[" + req.getMchntNo() + "]的商户，"+BompTxnNumEnum.mchntProdInfoManage.getDesc()+"交易出现异常，异常信息："+e.getMessage());
                return result;
            }
        } else {
            result = Maps.newHashMap();
            result.put("resCode", BusinessContainer.BSPS_SUCCESS);
            result.put("instId", entity.getInstId());
            result.put("mchntNo", entity.getMchntNo());
            result.put("optFlag", entity.getOptFlag());
            return result;
        }
    }

    @Override
    public Map<String, Object> signInfoShow(String instId, String mchntNo, String optFlag) throws RedpException {
        HashMap<String, Object> result = new HashMap<>();
        String queryType = "0";
        UpmpUserInfoVO user = CommonUtils.getCurrentUser(upmpSysParamService);
        CommonUtils.validateUserInst(instId, user);
        //查询基本信息正式表数据校验商户状态是否锁定
        MchntBaseInfoQueryResponse mchntBase = mchntBaseInfoQuery(instId, user, genMerOrder(instId), mchntNo, "", BompQueryTypeEnum.REAL, bompMchntQueryService);
        if (Common.isBlank(mchntBase)) {
            throw new RedpException("商户号[" + mchntNo + "]没有查询到对应的商户信息");
        }

        UpmpBMchntSignInfo entity = new UpmpBMchntSignInfo();
        entity.setInstId(instId);
        entity.setMchntNo(mchntNo);
        entity.setOprId(mchntBase.getOprId());
        entity.setRecordStatus(mchntBase.getMchntStatus());
        entity.setAuditStatus(mchntBase.getAuditStatus());
        entity.setMchntType(mchntBase.getMchntBaseInfo().getMchntType());
        entity.setCreateTime(DateUtils.formatDate(new Date(), "yyyy-MM-dd HH:mm:ss.SSS"));

        if (PageOptFlagEnum.OPT_FLAG_ADD.getType().equals(optFlag)) {
            entity.setRecordStatus(BizDataStatusEnum.STATUS_DRAFT.getType());
            entity.setAuditStatus(BizDataAuditStatusEnum.AUDIT_STATUS_ADD_NOTCOMMIT.getType());
        } else if (PageOptFlagEnum.OPT_FLAG_UPDATE.getType().equals(optFlag)
                || PageOptFlagEnum.OPT_FLAG_USE.getType().equals(optFlag)
                || PageOptFlagEnum.OPT_FLAG_STOP.getType().equals(optFlag)
                || PageOptFlagEnum.OPT_FLAG_CANCEL.getType().equals(optFlag)
                || PageOptFlagEnum.OPT_FLAG_VIEW.getType().equals(optFlag)
                || PageOptFlagEnum.OPT_FLAG_CHECK.getType().equals(optFlag)
                || PageOptFlagEnum.OPT_FLAG_CHECK_VIEW.getType().equals(optFlag)) {

            if ((BizDataAuditStatusEnum.AUDIT_STATUS_UPD_CHECKING.getType().equals(mchntBase.getAuditStatus())
                    || BizDataAuditStatusEnum.AUDIT_STATUS_STOP_CHECKING.getType().equals(mchntBase.getAuditStatus())
                    || BizDataAuditStatusEnum.AUDIT_STATUS_USE_CHECKING.getType().equals(mchntBase.getAuditStatus())
                    || BizDataAuditStatusEnum.AUDIT_STATUS_CANCEL_CHECKING.getType().equals(mchntBase.getAuditStatus()))
                    && !PageOptFlagEnum.OPT_FLAG_VIEW.getType().equals(optFlag)
                    && !PageOptFlagEnum.OPT_FLAG_CHECK.getType().equals(optFlag)
                    && !PageOptFlagEnum.OPT_FLAG_CHECK_VIEW.getType().equals(optFlag)) {
                throw new RedpException("商户号[" + mchntNo + "]的商户信息已被审批流程锁定！");
            }
            //调用商户签约信息查询接口根据商户号查询商户签约信息
            MchntSignInfoQueryRequest req = new MchntSignInfoQueryRequest();
            req.setMchntNo(mchntNo);
            req.setUserId(user.getId());
            MchntSignInfoQueryResponse entityDB;
            if (PageOptFlagEnum.OPT_FLAG_UPDATE.getType().equals(optFlag)
                    && (BizDataAuditStatusEnum.AUDIT_STATUS_UPD_REJECT.getType().equals(mchntBase.getAuditStatus()) || BizDataAuditStatusEnum.AUDIT_STATUS_ADD_REJECT.getType().equals(mchntBase.getAuditStatus())
                    || BizDataAuditStatusEnum.AUDIT_STATUS_UPD_NOTCOMMIT.getType().equals(mchntBase.getAuditStatus()) || BizDataAuditStatusEnum.AUDIT_STATUS_ADD_NOTCOMMIT.getType().equals(mchntBase.getAuditStatus())
                    || BizDataStatusEnum.STATUS_DRAFT.getType().equals(mchntBase.getMchntStatus()))) {
                //新增、修改拒绝时查询临时表数据
                entityDB = bMchntSignInfoService.mchntSignInfoQuery(instId, req, bompMchntQueryService, genMerOrder(instId), BompQueryTypeEnum.TEMP);
            } else if (PageOptFlagEnum.OPT_FLAG_CHECK.getType().equals(optFlag) || PageOptFlagEnum.OPT_FLAG_CHECK_VIEW.getType().equals(optFlag)) {
                entityDB = bMchntSignInfoService.mchntSignInfoQuery(instId, req, bompMchntQueryService, genMerOrder(instId), BompQueryTypeEnum.TEMP);

            } else {
                //查询正式表数据
                entityDB = bMchntSignInfoService.mchntSignInfoQuery(instId, req, bompMchntQueryService, genMerOrder(instId), BompQueryTypeEnum.REAL);
                queryType = "1";
            }
            if (Common.isNotBlank(entityDB)) {
                bMchntSignInfoService.buildBMchntSign(entityDB, entity);
                //TODO 审核对比功能屏蔽
                /*if ((PageOptFlagEnum.OPT_FLAG_CHECK.getType().equals(optFlag) || PageOptFlagEnum.OPT_FLAG_CHECK_VIEW.getType().equals(optFlag)) && BizDataAuditStatusEnum.AUDIT_STATUS_UPD_CHECKING.getType().equals(mchntBase.getAuditStatus())) {

                    MchntSignInfoQueryResponse entityDBReal = bMchntSignInfoService.mchntSignInfoQuery(instId, req, bompMchntQueryService, genMerOrder(instId), BompQueryTypeEnum.REAL);
                    UpmpBMchntSignInfo entityReal = new UpmpBMchntSignInfo();
                    bMchntSignInfoService.buildBMchntSign(entityDBReal, entityReal);
                    entityReal.setInstId(instId);

                    List<LabelValueBean> compareBeans = CommonUtils.compareData(entity, entityReal, UpmpBMchntSignInfo.class);
//                    List<LabelValueBean> removeCompareBeans = Lists.newArrayList();
                    for (LabelValueBean bean : compareBeans) {
                        if (Common.isNotBlank(bean.getValue())) {
                            String beanVal = bean.getValue();
                            if ("licenceType".equals(bean.getElabel())) {
                                beanVal = bean.getValue() + "-" + EnumUtils.getEnumDescriotionByValue(bean.getValue(), BompSignLicenceTypeEnum.class, "getType", "getDesc");
                            } else if ("enterRegisterType".equals(bean.getElabel())) {
                                beanVal = bean.getValue() + "-" + EnumUtils.getEnumDescriotionByValue(bean.getValue(), MchntEnterRegisterTypeEnum.class, "getType", "getDesc");
                            } else if ("registerProvince".equals(bean.getElabel())) {
                                beanVal = bean.getValue() + "-" + (Common.isBlank(entityDB.getBusinessLicenceInfo()) ? "" : entityReal.getRegisterProvinceName());
                            } else if ("registerCity".equals(bean.getElabel())) {
                                beanVal = bean.getValue() + "-" + (Common.isBlank(entityDB.getBusinessLicenceInfo()) ? "" : entityReal.getRegisterCityName());
                            } else if ("registerArea".equals(bean.getElabel())) {
                                beanVal = bean.getValue() + "-" + (Common.isBlank(entityDB.getBusinessLicenceInfo()) ? "" : entityReal.getRegisterAreaName());
                            } else if ("artifCertType".equals(bean.getElabel())) {
                                beanVal = bean.getValue() + "-" + EnumUtils.getEnumDescriotionByValue(bean.getValue(), BompArtifCertTypeEnum.class, "getType", "getDesc");
                            }
                            if ("licenceImage".equals(bean.getElabel())) {
                                //图片对象为空时目前联机返回时并不是返回null，而是返回了一个对象，对象里每个属性值都为null，需要进行过滤
                                if (Common.isBlank(entityReal.getLicenceImage()) || Common.isBlank(entityReal.getLicenceImage().getId())) {
                                    beanVal = "";
                                }
                            } else if ("certFaceImage".equals(bean.getElabel())) {
                                //图片对象为空时目前联机返回时并不是返回null，而是返回了一个对象，对象里每个属性值都为null，需要进行过滤
                                if (Common.isBlank(entityReal.getCertFaceImage()) || Common.isBlank(entityReal.getCertFaceImage().getId())) {
                                    beanVal = "";
                                }
                            } else if ("certBackImage".equals(bean.getElabel())) {
                                //图片对象为空时目前联机返回时并不是返回null，而是返回了一个对象，对象里每个属性值都为null，需要进行过滤
                                if (Common.isBlank(entityReal.getCertBackImage()) || Common.isBlank(entityReal.getCertBackImage().getId())) {
                                    beanVal = "";
                                }
                            }
                            bean.setValue(beanVal);
                        }
                    }
//                    compareBeans.removeAll(removeCompareBeans);
                    result.put("compareBeans", JSON.toJSONString(compareBeans));
                }*/
            }

        } else {
            log.error("不支持的操作");
            throw new RedpException("不支持的操作");
        }

        if ((mchntBase.getAuditStatus().equals(BizDataAuditStatusEnum.AUDIT_STATUS_ADD_NOTCOMMIT.getType()) && Common.isBlank(entity.getRegisterProvince())) ||
                ((mchntBase.getMchntBaseInfo().getMchntType().equals(MchntTypeEnum.SMALL_MICRO_MCHNT.getType()) &&
                        (Common.isBlank(entity.getRegisterProvince()) || Common.isBlank(entity.getRegisterArea()) || Common.isBlank(entity.getRegisterCity()) || Common.isBlank(entity.getRegisterAddr()))))) {
            entity.setRegisterProvince(mchntBase.getMchntBaseInfo().getMchntBizProvince());
            entity.setRegisterCity(mchntBase.getMchntBaseInfo().getMchntBizCity());
            entity.setRegisterArea(mchntBase.getMchntBaseInfo().getMchntBizRegion());
            entity.setRegisterAddr(mchntBase.getMchntBaseInfo().getMchntBizAddr());
        }

        if (Common.isNotBlank(mchntBase.getMchntContactsInfo().getContactMobile()) && Common.isBlank(entity.getArtifMobile())) {
            entity.setArtifMobile(mchntBase.getMchntContactsInfo().getContactMobile());
        }
        if (Common.isBlank(entity.getArtifCertType())) {
            entity.setArtifCertType("01");
            result.put("artifCertType", "add");
        }
        if (Common.isBlank(entity.getLicenceType())) {
            entity.setLicenceType("00");
            result.put("licenceType", "add");
        }

        result.put("baseProdCode", BaseProdCodeEnum.ALL_PROD.getType());

        //查询系统参数是否需要联网核查
        ParamQueryRequest req = new ParamQueryRequest();
        req.setUserId(user.getId());
        req.setParamType(BusinessContainer.MCMP_TO_BOMP_PARAM_TYPE); //待定
        req.setParamKey(ParamQueryKeyEnum.ON_LINE_CHECK_FLAG.getType()); //待定
        ParamQueryResponse paramResp = this.paramQuery(instId, req, genMerOrder(instId));
        if (Common.isNotBlank(paramResp)) {
            List<SysParamBean> sysParamList = paramResp.getSysParamList();
            if (CollectionUtils.isNotEmpty(sysParamList)) {
                result.put("onLineCheckFlag", sysParamList.get(0).getParamValue());
            }
        }

        //查询系统参数是否需要征信报告
        ParamQueryRequest reqCredit = new ParamQueryRequest();
        reqCredit.setUserId(user.getId());
        reqCredit.setParamType(BusinessContainer.MCMP_TO_BOMP_PARAM_TYPE);
        reqCredit.setParamKey(ParamQueryKeyEnum.CREDIT_REPORT_FLAG.getType());
        ParamQueryResponse creditResp = this.paramQuery(instId, reqCredit, genMerOrder(instId));
        if (Common.isNotBlank(creditResp)) {
            List<SysParamBean> sysParamList = creditResp.getSysParamList();
            if (CollectionUtils.isNotEmpty(sysParamList)) {
                result.put("creditReportFlag", sysParamList.get(0).getParamValue());
            }
        }


        ParamQueryRequest mchntAvgTransAmtreq = new ParamQueryRequest();
        mchntAvgTransAmtreq.setUserId(user.getId());
        mchntAvgTransAmtreq.setParamType(BusinessContainer.MCMP_TO_BOMP_PARAM_TYPE);
//        mchntAvgTransAmtreq.setParamKey(ParamQueryKeyEnum.REGISTER_CAPITAL.getType());
        mchntAvgTransAmtreq.setParamKey(ParamQueryKeyEnum.MCHNT_AVG_TRANS_AMT.getType());
        try {
            ParamQueryResponse paramQueryResponse = this.paramQuery(instId, mchntAvgTransAmtreq, genMerOrder(instId));
            if (Common.isNotBlank(paramQueryResponse)) {
                List<SysParamBean> sysParamList = paramQueryResponse.getSysParamList();
                if (CollectionUtils.isNotEmpty(sysParamList)) {
                    result.put("mchntAvgTransAmt", sysParamList.get(0).getParamValue());
                }
            }
        } catch (Exception e) {
            log.info(e.getMessage());
        }

        ParamQueryRequest registerCapitalReq = new ParamQueryRequest();
        registerCapitalReq.setUserId(user.getId());
        registerCapitalReq.setParamType(BusinessContainer.MCMP_TO_BOMP_PARAM_TYPE);
//        mchntAvgTransAmtreq.setParamKey(ParamQueryKeyEnum.REGISTER_CAPITAL.getType());
        registerCapitalReq.setParamKey(ParamQueryKeyEnum.REGISTER_CAPITAL.getType());
        try {
            ParamQueryResponse registerCapitalResp = this.paramQuery(instId, mchntAvgTransAmtreq, genMerOrder(instId));
            if (Common.isNotBlank(registerCapitalResp)) {
                List<SysParamBean> sysParamList = registerCapitalResp.getSysParamList();
                if (CollectionUtils.isNotEmpty(sysParamList)) {
                    result.put("registerCapitalFlag", sysParamList.get(0).getParamValue());
                }
            }
        } catch (Exception e) {
            log.info(e.getMessage());
        }


        RegionInfoQueryRequest place = new RegionInfoQueryRequest();
        place.setPageIndex(-1);//联机页码从0开始，select2页码从1开始
        place.setPageSize(-1);
        place.setUserId(user.getId());
        if (Common.isNotBlank(entity.getRegisterProvince())) {
            place.setRegionLevel("01");
            place.setRegionName(entity.getRegisterProvince());
            try {
                RegionInfoQueryResponse regionInfoQueryResponse = this.registerListQuery(entity.getInstId(), user, place, bompPublicQueryService, genMerOrder(entity.getInstId()));
                result.put("registerProvinceName", regionInfoQueryResponse.getRegionInfoList().get(0).getRegionName());
            } catch (Exception e) {
                log.info(e.getMessage());
            }
        }

        if (Common.isNotBlank(entity.getRegisterCity())) {
            place.setSuperRegionCode(entity.getRegisterProvince());
            place.setRegionLevel("02");
            place.setRegionName(entity.getRegisterCity());
            try {
                RegionInfoQueryResponse regionInfoQueryResponse = this.registerListQuery(entity.getInstId(), user, place, bompPublicQueryService, genMerOrder(entity.getInstId()));
                result.put("registerCityName", regionInfoQueryResponse.getRegionInfoList().get(0).getRegionName());
            } catch (Exception e) {
                log.info(e.getMessage());
            }
        }

        if (Common.isNotBlank(entity.getRegisterArea())) {
            place.setSuperRegionCode(entity.getRegisterCity());
            place.setRegionLevel("03");
            place.setRegionName(entity.getRegisterArea());
            try {
                RegionInfoQueryResponse regionInfoQueryResponse = this.registerListQuery(entity.getInstId(), user, place, bompPublicQueryService, genMerOrder(entity.getInstId()));
                result.put("registerAreaName", regionInfoQueryResponse.getRegionInfoList().get(0).getRegionName());
            } catch (Exception e) {
                log.info(e.getMessage());
            }
        }
        if (Common.isNotBlank(entity.getLicenceExpiryDate())) {
            if (entity.getLicenceExpiryDate().equals("99991231") || entity.getLicenceExpiryDate().equals("20991231")) {
                entity.setLicenceExpiryDate("长期");
            }
        }
        if (Common.isNotBlank(entity.getCertExpiryDate())) {
            if (entity.getCertExpiryDate().equals("99991231") || entity.getCertExpiryDate().equals("20991231")) {
                entity.setCertExpiryDate("长期");
            }
        }


        entity.setOptFlag(optFlag);
        result.put("clazz", "cc.rengu.ecp.platform.mcmp.entity.BMchntSignInfo");
        result.put("entity", entity);
        result.put("instId", instId);
        result.put("mchntNo", mchntNo);
        result.put("optFlag", optFlag);
        result.put("queryType", queryType);
        result.put("mchntType", mchntBase.getMchntBaseInfo().getMchntType());


        return result;
    }

    @Override
    public Map<String, Object> signInfoSave(UpmpBMchntSignInfo entity) throws RedpException {
        HashMap<String, Object> result = new HashMap<>();
        UpmpUserInfoVO user = CommonUtils.getCurrentUser(upmpSysParamService);
        CommonUtils.validateUserInst(entity.getInstId(), user);
        if (Common.isNotBlank(entity.getLicenceExpiryDate())) {
            if (entity.getLicenceExpiryDate().equals("长期")) {
                entity.setLicenceExpiryDate("99991231");
            }
        }
        if (Common.isNotBlank(entity.getCertExpiryDate())) {
            if (entity.getCertExpiryDate().equals("长期")) {
                entity.setCertExpiryDate("99991231");
            }
        }
        if (PageOptFlagEnum.OPT_FLAG_ADD.getType().equals(entity.getOptFlag())
                || PageOptFlagEnum.OPT_FLAG_UPDATE.getType().equals(entity.getOptFlag())) {
            MchntSignInfoManageRequest req = new MchntSignInfoManageRequest();
            BeanUtils.copyProperties(entity, req);
            BusinessLicenceInfoBean businessLicenceInfo = new BusinessLicenceInfoBean();
            BeanUtils.copyProperties(entity, businessLicenceInfo);
            if (Common.isNotBlank(entity.getLicenceImage())) {
                SignImageInfoBean img = new SignImageInfoBean();
                BeanUtils.copyProperties(entity.getLicenceImage(), img);
                businessLicenceInfo.setSignImageInfoBean(img);
            }
            req.setBusinessLicenceInfoBean(businessLicenceInfo);
            MchntArtifInfoBean mchntArtifInfo = new MchntArtifInfoBean();
            BeanUtils.copyProperties(entity, mchntArtifInfo);
            if (Common.isNotBlank(entity.getCertFaceImage())) {
                SignImageInfoBean img = new SignImageInfoBean();
                BeanUtils.copyProperties(entity.getCertFaceImage(), img);
                mchntArtifInfo.setCertFaceImage(img);
            }
            if (Common.isNotBlank(entity.getCertBackImage())) {
                SignImageInfoBean img = new SignImageInfoBean();
                BeanUtils.copyProperties(entity.getCertBackImage(), img);
                mchntArtifInfo.setCertBackImage(img);
            }
            req.setMchntArtifInfoBean(mchntArtifInfo);
            req.setUserId(user.getId());
            //新增操作先查一次看之前是否已经保存，如果已经保存则修改
            if (PageOptFlagEnum.OPT_FLAG_ADD.getType().equals(entity.getOptFlag())) {
                MchntSignInfoQueryRequest reqQry = new MchntSignInfoQueryRequest();
                reqQry.setMchntNo(entity.getMchntNo());
                reqQry.setUserId(user.getId());
                MchntSignInfoQueryResponse resp = bMchntSignInfoService.mchntSignInfoQuery(entity.getInstId(), reqQry, bompMchntQueryService, genMerOrder(entity.getInstId()), BompQueryTypeEnum.REAL);
                if (Common.isNotBlank(resp)) {//如果应答非空则认为是修改
                    entity.setOptFlag(PageOptFlagEnum.OPT_FLAG_UPDATE.getType());
                }
            }
            String traceNo = genMerOrder(entity.getInstId());
            String optFlag = entity.getOptFlag();
            String instId = entity.getInstId();
            /**商户写死必须审核*/
            req.setHeader(CommonUtils.packageBompHeader(traceNo, BompTxnNumEnum.mchntSignInfoManage.getType(), instId, null));
            if (PageOptFlagEnum.OPT_FLAG_ADD.getType().equals(optFlag)) {
                req.setOprType(BompManageOprTypeEnum.CREATE.getType());
                UpmpPrivilegeCheck privilegeCheck = upmpPrivilegeCheckService.getPrivilegeCheckByPrivilegeCode(entity.getInstId(),
                        oprBtnNamePrefix + BusinessContainer.AUTH_PRIVILEGE_CODE_SPLIT + PageOptFlagEnum.OPT_FLAG_ADD.getDesc());
                if (null != privilegeCheck && BusinessContainer.YES.equals(privilegeCheck.getChecked())) {
                    req.setChecked(BompAuditFlagEnum.CHECK.getType());
                    req.setOprMenuId(oprMenuId);
                    req.setOprMenuName(oprMenuName);
                    req.setWebNextUrl(webNextUrl);
                    //设置主记录是否需要显示
                    req.setMasterShowFlag(IgasYesOrNoEnum.No.getType());

                } else {
                /*req.setChecked(BompAuditFlagEnum.NO_CHECK.getType());
                //设置主记录是否需要显示
                req.setMasterShowFlag(IgasYesOrNoEnum.No.getType());*/
                    req.setChecked(BompAuditFlagEnum.CHECK.getType());
                    req.setOprMenuId(oprMenuId);
                    req.setOprMenuName(oprMenuName);
                    req.setWebNextUrl(webNextUrl);
                    //设置主记录是否需要显示
                    req.setMasterShowFlag(IgasYesOrNoEnum.No.getType());
                }
            } else if (PageOptFlagEnum.OPT_FLAG_UPDATE.getType().equals(optFlag)) {

                req.setOprType(BompManageOprTypeEnum.MODIFY.getType());
                UpmpPrivilegeCheck privilegeCheck = upmpPrivilegeCheckService.getPrivilegeCheckByPrivilegeCode(entity.getInstId(),
                        oprBtnNamePrefix + BusinessContainer.AUTH_PRIVILEGE_CODE_SPLIT + PageOptFlagEnum.OPT_FLAG_UPDATE.getDesc());

                if (null != privilegeCheck && BusinessContainer.YES.equals(privilegeCheck.getChecked())) {
                    req.setChecked(BompAuditFlagEnum.CHECK.getType());
                    req.setOprMenuId(oprMenuId);
                    req.setOprMenuName(oprMenuName);
                    req.setWebNextUrl(webNextUrl);
                    //设置主记录是否需要显示
                    req.setMasterShowFlag(IgasYesOrNoEnum.No.getType());

                } else {
                    /*req.setChecked(BompAuditFlagEnum.NO_CHECK.getType());
                    //设置主记录是否需要显示
                    req.setMasterShowFlag(IgasYesOrNoEnum.No.getType());*/
                    req.setChecked(BompAuditFlagEnum.CHECK.getType());
                    req.setOprMenuId(oprMenuId);
                    req.setOprMenuName(oprMenuName);
                    req.setWebNextUrl(webNextUrl);
                    //设置主记录是否需要显示
                    req.setMasterShowFlag(IgasYesOrNoEnum.No.getType());
                }
            } else {
                throw new RedpException("不支持的操作");
            }
            try {

                log.info("法人行[" + instId + "],用户标识[" + req.getUserId() + "],商户号[" + req.getMchntNo() + "]" + BompTxnNumEnum.mchntSignInfoManage.getDesc() + "交易请求报文：" + JSON.toJSONString(req));

                Result<MchntSignInfoManageResponse> response = bompMchntManageService.mchntSignInfoManage(req);

                log.info("法人行[" + instId + "],用户标识[" + req.getUserId() + "],商户号[" + req.getMchntNo() + "]" + BompTxnNumEnum.mchntSignInfoManage.getDesc() + "交易返回报文：" + JSON.toJSONString(response));
                if (response.isSuccess()) {
                    MchntSignInfoManageResponse resp = response.getResult();
                    // 返回码：00-进件成功，其他均视为失败
                    if (BusinessContainer.BSPS_SUCCESS.equals(resp.getRespCode())) {
                        result.put("respCode", resp.getRespCode());
                        result.put("respMsg", resp.getRespDesc());

                        result.put("instId", instId);
                        result.put("mchntNo", req.getMchntNo());
                        result.put("optFlag", optFlag);
                        log.info("法人行[" + instId + "],用户标识[" + req.getUserId() + "],商户号[" + req.getMchntNo() + "]" + BompTxnNumEnum.mchntSignInfoManage.getDesc() + "交易成功");
                        return result;
                    } else {
                        if (resp.getRespCode().equals(RespCodeEnum.BUSINESS_LICENSE_REPEAT.getRespCode()) || resp.getRespCode().equals("ES000096")) {
                            return result;
                        }
                        result.put("respCode", resp.getRespCode());
                        result.put("respMsg", resp.getRespDesc());
                        return result;
                    }
                } else {
                    result.put("resCode", BusinessContainer.ERROR);
                    result.put("resMsg", BompTxnNumEnum.mchntSignInfoManage.getDesc() + "没有获得返回报文");
                    log.error("法人行[" + instId + "],用户标识[" + req.getUserId() + "],商户号[" + req.getMchntNo() + "]" + BompTxnNumEnum.mchntSignInfoManage.getDesc() + "交易没有获得返回信息");
                    return result;
                }
            } catch (Exception e) {
                // TODO: handle exception
                result.put("resCode", BusinessContainer.ERROR);
                result.put("resMsg", e.getMessage());
                log.error("法人行[" + instId + "],用户标识[" + req.getUserId() + "],商户号[" + req.getMchntNo() + "]" + BompTxnNumEnum.mchntSignInfoManage.getDesc() + "交易出现异常，异常信息：" + e.getMessage(), e);
//            throw new RedpException("商户编号为：" + req.getMchntNo() + "的商户，"+BompTxnNumEnum.mchntProdInfoManage.getDesc()+"交易出现异常，异常信息："+e.getMessage());
                return result;
            }
        } else {
            result = Maps.newHashMap();
            result.put("instId", entity.getInstId());
            result.put("mchntNo", entity.getMchntNo());
            result.put("optFlag", entity.getOptFlag());
            return result;
        }
    }

    @Override
    public Map<String, Object> editMchntImage(String instId, String mchntNo, String optFlag) throws RedpException {
        HashMap<String, Object> result = new HashMap<>();
        String flag = "Y";
        String queryType = "0";
        UpmpUserInfoVO user = CommonUtils.getCurrentUser(upmpSysParamService);
        CommonUtils.validateUserInst(instId, user);
        MchntBaseInfoQueryResponse mchntBase;
        MchntImageManageVO vo;
        if (PageOptFlagEnum.OPT_FLAG_ADD.getType().equals(optFlag)) {
            vo = new MchntImageManageVO();
            vo.setMchntNo(mchntNo);
            vo.setInstId(instId);
            vo.setOptFlag(optFlag);
//            vo.setMchntSignId("801200500000001");
        } else if (PageOptFlagEnum.OPT_FLAG_UPDATE.getType().equals(optFlag)
                || PageOptFlagEnum.OPT_FLAG_USE.getType().equals(optFlag)
                || PageOptFlagEnum.OPT_FLAG_STOP.getType().equals(optFlag)
                || PageOptFlagEnum.OPT_FLAG_CANCEL.getType().equals(optFlag)
                || PageOptFlagEnum.OPT_FLAG_VIEW.getType().equals(optFlag)
                || PageOptFlagEnum.OPT_FLAG_CHECK.getType().equals(optFlag)
                || PageOptFlagEnum.OPT_FLAG_CHECK_VIEW.getType().equals(optFlag)) {
            //查询基本信息正式表数据校验商户状态是否锁定
            mchntBase = this.mchntBaseInfoQuery(instId, user, this.genMerOrder(instId), mchntNo, "", BompQueryTypeEnum.REAL, bompMchntQueryService);
            if (Common.isBlank(mchntBase)) {
                throw new RedpException("商户号[" + mchntNo + "]没有查询到对应的商户信息");
            }

            if ((BizDataAuditStatusEnum.AUDIT_STATUS_UPD_CHECKING.getType().equals(mchntBase.getAuditStatus())
                    || BizDataAuditStatusEnum.AUDIT_STATUS_STOP_CHECKING.getType().equals(mchntBase.getAuditStatus())
                    || BizDataAuditStatusEnum.AUDIT_STATUS_USE_CHECKING.getType().equals(mchntBase.getAuditStatus())
                    || BizDataAuditStatusEnum.AUDIT_STATUS_CANCEL_CHECKING.getType().equals(mchntBase.getAuditStatus()))
                    && !PageOptFlagEnum.OPT_FLAG_VIEW.getType().equals(optFlag)
                    && !PageOptFlagEnum.OPT_FLAG_CHECK.getType().equals(optFlag)
                    && !PageOptFlagEnum.OPT_FLAG_CHECK_VIEW.getType().equals(optFlag)) {
                throw new RedpException("商户号[" + mchntNo + "]的商户信息已被审批流程锁定！");
            }
            //调用商户签约信息查询接口根据商户号查询商户签约信息
            MchntImageInfoQueryRequest req = new MchntImageInfoQueryRequest();
            req.setMchntNo(mchntNo);
            req.setUserId(user.getId());

            MchntImageInfoQueryResponse entity;
            if (PageOptFlagEnum.OPT_FLAG_UPDATE.getType().equals(optFlag)
                    && (BizDataAuditStatusEnum.AUDIT_STATUS_UPD_REJECT.getType().equals(mchntBase.getAuditStatus()) || BizDataAuditStatusEnum.AUDIT_STATUS_ADD_REJECT.getType().equals(mchntBase.getAuditStatus())
                    || BizDataAuditStatusEnum.AUDIT_STATUS_UPD_NOTCOMMIT.getType().equals(mchntBase.getAuditStatus()) || BizDataAuditStatusEnum.AUDIT_STATUS_ADD_NOTCOMMIT.getType().equals(mchntBase.getAuditStatus())
                    || BizDataStatusEnum.STATUS_DRAFT.getType().equals(mchntBase.getMchntStatus()))) {
                //新增、修改拒绝时查询临时表数据
                entity = bMchntImageInfoService.mchntImageInfoQuery(instId, req, bompMchntQueryService, this.genMerOrder(instId), BompQueryTypeEnum.TEMP);
            } else if (PageOptFlagEnum.OPT_FLAG_CHECK.getType().equals(optFlag) || PageOptFlagEnum.OPT_FLAG_CHECK_VIEW.getType().equals(optFlag)) {
                entity = bMchntImageInfoService.mchntImageInfoQuery(instId, req, bompMchntQueryService, this.genMerOrder(instId), BompQueryTypeEnum.TEMP);
                //TODO 审核对比功能屏蔽
                /*if (BizDataAuditStatusEnum.AUDIT_STATUS_UPD_CHECKING.getType().equals(mchntBase.getAuditStatus())) {
                    MchntImageInfoQueryResponse entityReal = bMchntImageInfoService.mchntImageInfoQuery(instId, req, bompMchntQueryService, this.genMerOrder(instId), BompQueryTypeEnum.REAL);
                    if (CollectionUtils.isNotEmpty(entityReal.getMchntImageInfoList())) {
                        MchntImageManageVO voReal = new MchntImageManageVO();
                        bMchntImageInfoService.getMchntImageVo(entityReal, voReal);
                        voReal.setInstId(instId);
                        voReal.setMchntNo(mchntNo);
                        vo = new MchntImageManageVO();
                        bMchntImageInfoService.getMchntImageVo(entity, vo);
                        vo.setInstId(instId);
                        vo.setOptFlag(optFlag);
                        //初次筛查，对于数组或对象数组，可能因为子元素顺序不一样，导致转成jsonString 不一样
                        List<LabelValueBean> compareBeans = CommonUtils.compareData(vo, voReal, MchntImageManageVO.class);
                        if (CollectionUtils.isNotEmpty(compareBeans)) {
                            bMchntImageInfoService.compareImgList(vo, voReal, compareBeans);
                        }
                        //获取修改、删除的附件，目前界面以前后全量对比的方式实现图片、附件审核时的前后对比
                        if (CollectionUtils.isNotEmpty(vo.getOtherFileList()) && CollectionUtils.isNotEmpty(voReal.getOtherFileList())) {
                            CompareDataBean compareFileList = bMchntImageInfoService.getCompareFileById(vo.getOtherFileList(), voReal.getOtherFileList());
                            if (Common.isNotBlank(compareFileList)) {
                                //修改的附件
                                if (Common.isNotBlank(compareFileList.getUpdCompare())) {
                                    LabelValueBean upd = new LabelValueBean();
                                    upd.setElabel("OtherFileUpdList");
                                    upd.setValue(JSON.toJSONString(compareFileList.getUpdCompare()));
                                    compareBeans.add(upd);
                                }
                                //删除的附件
                                if (Common.isNotBlank(compareFileList.getDelCompare())) {
                                    LabelValueBean del = new LabelValueBean();
                                    del.setElabel("OtherFileDelList");
                                    del.setValue(JSON.toJSONString(compareFileList.getUpdCompare()));
                                    compareBeans.add(del);
                                }
                            }
                        }


                        result.put("compareBeans", JSON.toJSONString(compareBeans));
                        result.put("entityReal", voReal);

                    }
                }*/
            } else {
                //查询正式表数据
                entity = bMchntImageInfoService.mchntImageInfoQuery(instId, req, bompMchntQueryService, this.genMerOrder(instId), BompQueryTypeEnum.REAL);
                queryType = "1";
            }

            vo = new MchntImageManageVO();
            vo.setOptFlag(optFlag);
            if (Common.isNotBlank(entity)) {
                bMchntImageInfoService.getMchntImageVo(entity, vo);
            }
            vo.setInstId(instId);
        } else {
            log.error("不支持的操作");
            throw new RedpException("不支持的操作");
        }

        //判断商户为连锁门店商户并且非独立维护商户资料控制界面提交按钮
        mchntBase = this.mchntBaseInfoQuery(instId, user, this.genMerOrder(instId), mchntNo, "", BompQueryTypeEnum.REAL, bompMchntQueryService);
        if (mchntBase.getMchntBaseInfo().getMchntType().equals("11") && mchntBase.getMchntBaseInfo().getIndependentDataFlag().equals("N")) {
            flag = "N";
        }

        ParamQueryRequest req = new ParamQueryRequest();
        req.setUserId(user.getId());
        req.setParamKey(ParamQueryKeyEnum.OTHER_FILE_LIST.getType());
        req.setParamType(BusinessContainer.MCMP_TO_BOMP_PARAM_TYPE);
        ParamQueryResponse paramQueryResponse = this.paramQuery(instId, req, this.genMerOrder(instId));
        if (Common.isNotBlank(paramQueryResponse)) {
            List<SysParamBean> sysParamList = paramQueryResponse.getSysParamList();
            if (CollectionUtils.isNotEmpty(sysParamList)) {
                result.put("otherFileList", sysParamList.get(0).getParamValue());
            }
        }

        result.put("entity", vo);
        result.put("flag", flag);
        result.put("queryType", queryType);
        result.put("mchntType", mchntBase.getMchntBaseInfo().getMchntType());
        result.put("auditStatus", mchntBase.getAuditStatus());
        result.put("mchntStopReason", mchntBase.getMchntStopReason());
        result.put("mchntCancelReason", mchntBase.getMchntCancelReason());
        result.put("auditRefuseReason", mchntBase.getAuditRefuseReason());

        return result;
    }

    @Override
    public OperationResult mchntImageSave(MchntImageManageVO entity) throws RedpException {
        UpmpUserInfoVO user = CommonUtils.getCurrentUser(upmpSysParamService);
        CommonUtils.validateUserInst(entity.getInstId(), user);
        //查询商户基本信息表
        MchntBaseInfoQueryResponse mchntBase
                = mchntBaseInfoQuery(entity.getInstId(), user, genMerOrder(entity.getInstId()), entity.getMchntNo(), "", BompQueryTypeEnum.REAL, bompMchntQueryService);
        if (PageOptFlagEnum.OPT_FLAG_ADD.getType().equals(entity.getOptFlag())
                || PageOptFlagEnum.OPT_FLAG_UPDATE.getType().equals(entity.getOptFlag())) {
            //新增操作先查一次看之前是否已经保存，如果已经保存则修改
            if (PageOptFlagEnum.OPT_FLAG_ADD.getType().equals(entity.getOptFlag())) {
                MchntImageInfoQueryRequest reqQry = new MchntImageInfoQueryRequest();
                reqQry.setMchntNo(entity.getMchntNo());
                reqQry.setUserId(user.getId());
                MchntImageInfoQueryResponse resp = bMchntImageInfoService.mchntImageInfoQuery(entity.getInstId(), reqQry, bompMchntQueryService, genMerOrder(entity.getInstId()), BompQueryTypeEnum.REAL);
                if (Common.isNotBlank(resp)) {//如果应答非空则认为是修改
                    entity.setOptFlag(PageOptFlagEnum.OPT_FLAG_UPDATE.getType());
                }
            }
            MchntImageInfoManageRequest req = new MchntImageInfoManageRequest();
            req.setUserId(user.getId());
            bMchntImageInfoService.getMchntImageManage(req, entity);
            OperationResult operationResult = mchntImageInfoManage(entity.getInstId(), req, genMerOrder(entity.getInstId()), entity.getOptFlag());
            mchntBase = mchntBaseInfoQuery(entity.getInstId(), user, genMerOrder(entity.getInstId()), entity.getMchntNo(), "", BompQueryTypeEnum.TEMP, bompMchntQueryService);
            if (mchntBase.getMchntBaseInfo().getMchntType().equals("11") && mchntBase.getMchntBaseInfo().getIndependentDataFlag().equals("N")) {
                Map<String, Object> data = (Map<String, Object>) operationResult.getData();
                data.put("optFlag", entity.getOptFlag());
                data.put("mchntNo", entity.getMchntNo());
                data.put("instId", entity.getInstId());
                data.put("mchntType", mchntBase.getMchntBaseInfo().getMchntType());
                data.put("independentDataFlag", mchntBase.getMchntBaseInfo().getIndependentDataFlag());
                data.put("flag", entity.getFlag());
            }
            //判断商户是否为连锁商户且不是独立维护商户资料的
            return operationResult;


        } else {
            Map<String, Object> result = Maps.newHashMap();
            result.put("instId", entity.getInstId());
            result.put("mchntNo", entity.getMchntNo());
            result.put("optFlag", entity.getOptFlag());
            OperationResult operationResult = OperationResult.buildSuccessResult(BompTxnNumEnum.mchntBaseInfoManage.getDesc() + "交易成功", result);
            if (mchntBase.getMchntBaseInfo().getMchntType().equals("11") && mchntBase.getMchntBaseInfo().getIndependentDataFlag().equals("N")) {
                Map<String, Object> data = (Map<String, Object>) operationResult.getData();
                data.put("optFlag", entity.getOptFlag());
                data.put("mchntNo", entity.getMchntNo());
                data.put("instId", entity.getInstId());
                data.put("mchntType", mchntBase.getMchntBaseInfo().getMchntType());
                data.put("independentDataFlag", mchntBase.getMchntBaseInfo().getIndependentDataFlag());
                data.put("flag", entity.getFlag());
            }
            return operationResult;
        }
    }

    public OperationResult mchntImageInfoManage(String instId, MchntImageInfoManageRequest req, String traceNo, String optFlag) throws RedpException {
        UpmpUserInfoVO user = CommonUtils.getCurrentUser(upmpSysParamService);
        /**商户写死必须审核*/
        req.setHeader(CommonUtils.packageBompHeader(traceNo, BompTxnNumEnum.mchntImageInfoManage.getType(), instId, null));
        if (PageOptFlagEnum.OPT_FLAG_ADD.getType().equals(optFlag)) {
            req.setOprType(BompManageOprTypeEnum.CREATE.getType());
            UpmpPrivilegeCheck privilegeCheck = upmpPrivilegeCheckService.getPrivilegeCheckByPrivilegeCode(instId,
                    oprBtnNamePrefix + BusinessContainer.AUTH_PRIVILEGE_CODE_SPLIT + PageOptFlagEnum.OPT_FLAG_ADD.getDesc());
            if (null != privilegeCheck && BusinessContainer.YES.equals(privilegeCheck.getChecked())) {
                req.setChecked(BompAuditFlagEnum.CHECK.getType());
                req.setOprMenuId(oprMenuId);
                req.setOprMenuName(oprMenuName);
                req.setWebNextUrl(webNextUrl);
                //设置主记录是否需要显示
                req.setMasterShowFlag(IgasYesOrNoEnum.No.getType());

            } else {
                /*req.setChecked(BompAuditFlagEnum.NO_CHECK.getType());
                //设置主记录是否需要显示
                req.setMasterShowFlag(IgasYesOrNoEnum.No.getType());*/
                req.setChecked(BompAuditFlagEnum.CHECK.getType());
                req.setOprMenuId(oprMenuId);
                req.setOprMenuName(oprMenuName);
                req.setWebNextUrl(webNextUrl);
                //设置主记录是否需要显示
                req.setMasterShowFlag(IgasYesOrNoEnum.No.getType());
            }
        } else if (PageOptFlagEnum.OPT_FLAG_UPDATE.getType().equals(optFlag)) {

            req.setOprType(BompManageOprTypeEnum.MODIFY.getType());
            UpmpPrivilegeCheck privilegeCheck = upmpPrivilegeCheckService.getPrivilegeCheckByPrivilegeCode(instId,
                    oprBtnNamePrefix + BusinessContainer.AUTH_PRIVILEGE_CODE_SPLIT + PageOptFlagEnum.OPT_FLAG_UPDATE.getDesc());

            if (null != privilegeCheck && BusinessContainer.YES.equals(privilegeCheck.getChecked())) {
                req.setChecked(BompAuditFlagEnum.CHECK.getType());
                req.setOprMenuId(oprMenuId);
                req.setOprMenuName(oprMenuName);
                req.setWebNextUrl(webNextUrl);
                //设置主记录是否需要显示
                req.setMasterShowFlag(IgasYesOrNoEnum.No.getType());

            } else {
                    /*req.setChecked(BompAuditFlagEnum.NO_CHECK.getType());
                    //设置主记录是否需要显示
                    req.setMasterShowFlag(IgasYesOrNoEnum.No.getType());*/
                req.setChecked(BompAuditFlagEnum.CHECK.getType());
                req.setOprMenuId(oprMenuId);
                req.setOprMenuName(oprMenuName);
                req.setWebNextUrl(webNextUrl);
                //设置主记录是否需要显示
                req.setMasterShowFlag(IgasYesOrNoEnum.No.getType());
            }
        } else {
            throw new RedpException("不支持的操作");
        }
        Map<String, Object> result = Maps.newHashMap();
        try {

            log.info("法人行[" + instId + "],用户标识[" + req.getUserId() + "],商户号[" + req.getMchntNo() + "]" + BompTxnNumEnum.mchntImageInfoManage.getDesc() + "交易请求报文：" + JSON.toJSONString(req));

            Result<MchntImageInfoManageResponse> response = bompMchntManageService.mchntImageInfoManage(req);

            log.info("法人行[" + instId + "],用户标识[" + req.getUserId() + "],商户号[" + req.getMchntNo() + "]" + BompTxnNumEnum.mchntImageInfoManage.getDesc() + "交易返回报文：" + JSON.toJSONString(response));
            if (response.isSuccess()) {
                MchntImageInfoManageResponse resp = response.getResult();
                // 返回码：00-进件成功，其他均视为失败
                if (BusinessContainer.BSPS_SUCCESS.equals(resp.getRespCode())) {
                    result.put("respCode", resp.getRespCode());
                    result.put("respMsg", resp.getRespDesc());

                    result.put("instId", instId);
                    result.put("mchntNo", req.getMchntNo());
                    result.put("optFlag", optFlag);
                    log.info("法人行[" + instId + "],用户标识[" + req.getUserId() + "],商户号[" + req.getMchntNo() + "]" + BompTxnNumEnum.mchntImageInfoManage.getDesc() + "交易成功");
                    return OperationResult.buildSuccessResult(BompTxnNumEnum.mchntImageInfoManage.getDesc() + "交易成功", result);
                } else {
                    if (resp.getRespCode().equals("ER12BM74") || resp.getRespCode().equals("ES000096")) {
                        return OperationResult.buildFailureResult(resp.getRespDesc(), result);
                    }
                    result.put("respCode", resp.getRespCode());
                    result.put("respMsg", resp.getRespDesc());
                    return OperationResult.buildFailureResult(BompTxnNumEnum.mchntImageInfoManage.getDesc() + "交易失败", result);
                }
            } else {
                result.put("resCode", BusinessContainer.ERROR);
                result.put("resMsg", BompTxnNumEnum.mchntImageInfoManage.getDesc() + "没有获得返回报文");
                log.error("法人行[" + instId + "],用户标识[" + req.getUserId() + "],商户号[" + req.getMchntNo() + "]" + BompTxnNumEnum.mchntImageInfoManage.getDesc() + "交易没有获得返回信息");
                return OperationResult.buildFailureResult(BompTxnNumEnum.mchntImageInfoManage.getDesc() + "交易失败", result);
            }
        } catch (Exception e) {
            // TODO: handle exception
            result.put("resCode", BusinessContainer.ERROR);
            result.put("resMsg", e.getMessage());
            log.error("法人行[" + instId + "],用户标识[" + req.getUserId() + "],商户号[" + req.getMchntNo() + "]" + BompTxnNumEnum.mchntImageInfoManage.getDesc() + "交易出现异常，异常信息：" + e.getMessage(), e);
            return OperationResult.buildFailureResult(BompTxnNumEnum.mchntImageInfoManage.getDesc() + "交易失败", result);
        }
    }

    @Override
    public Map<String, Object> mchntAcctShow(String instId, String mchntNo, String optFlag) throws RedpException {
        HashMap<String, Object> result = new HashMap<>();
        String queryType = "";
        UpmpUserInfoVO user = CommonUtils.getCurrentUser(upmpSysParamService);
        CommonUtils.validateUserInst(instId, user);
        MchntBaseInfoQueryResponse mchntBase = mchntBaseInfoQuery(instId, user, genMerOrder(instId), mchntNo, "", BompQueryTypeEnum.REAL, bompMchntQueryService);
        MchntSettleInfoManageVO vo;
        if (PageOptFlagEnum.OPT_FLAG_ADD.getType().equals(optFlag)) {
            vo = new MchntSettleInfoManageVO();
            vo.setMchntNo(mchntNo);
            vo.setInstId(instId);
            vo.setRealSettleFlag(IgasYesOrNoEnum.No.getType());
            vo.setCashWithdrawalFlag(IgasYesOrNoEnum.No.getType());
            vo.setMchntSettleMode(MchntSettleModeEnum.MERGE_BUSINESS_SETTLE.getType());
            result.put("d0Flag", IgasYesOrNoEnum.No.getType());
            result.put("innerChannelD0Flag", IgasYesOrNoEnum.No.getType());
            result.put("cashDrawFlag", IgasYesOrNoEnum.No.getType());
        } else if (PageOptFlagEnum.OPT_FLAG_UPDATE.getType().equals(optFlag)
                || PageOptFlagEnum.OPT_FLAG_USE.getType().equals(optFlag)
                || PageOptFlagEnum.OPT_FLAG_STOP.getType().equals(optFlag)
                || PageOptFlagEnum.OPT_FLAG_CANCEL.getType().equals(optFlag)
                || PageOptFlagEnum.OPT_FLAG_VIEW.getType().equals(optFlag)
                || PageOptFlagEnum.OPT_FLAG_CHECK.getType().equals(optFlag)
                || PageOptFlagEnum.OPT_FLAG_CHECK_VIEW.getType().equals(optFlag)) {

            //查询基本信息正式表数据校验商户状态是否锁定
            if (Common.isBlank(mchntBase)) {
                throw new RedpException("商户号[" + mchntNo + "]没有查询到对应的商户信息");
            }

            if ((BizDataAuditStatusEnum.AUDIT_STATUS_UPD_CHECKING.getType().equals(mchntBase.getAuditStatus())
                    || BizDataAuditStatusEnum.AUDIT_STATUS_STOP_CHECKING.getType().equals(mchntBase.getAuditStatus())
                    || BizDataAuditStatusEnum.AUDIT_STATUS_USE_CHECKING.getType().equals(mchntBase.getAuditStatus())
                    || BizDataAuditStatusEnum.AUDIT_STATUS_CANCEL_CHECKING.getType().equals(mchntBase.getAuditStatus()))
                    && !PageOptFlagEnum.OPT_FLAG_VIEW.getType().equals(optFlag)
                    && !PageOptFlagEnum.OPT_FLAG_CHECK.getType().equals(optFlag)
                    && !PageOptFlagEnum.OPT_FLAG_CHECK_VIEW.getType().equals(optFlag)) {
                throw new RedpException("商户号[" + mchntNo + "]的商户信息已被审批流程锁定！");
            }
            MchntSettleAcctInfoQueryRequest req = new MchntSettleAcctInfoQueryRequest();
            req.setMchntNo(mchntNo);
            req.setUserId(user.getId());

            MchntSettleAcctInfoQueryResponse entity;
            if (PageOptFlagEnum.OPT_FLAG_UPDATE.getType().equals(optFlag)
                    && (BizDataAuditStatusEnum.AUDIT_STATUS_UPD_REJECT.getType().equals(mchntBase.getAuditStatus()) || BizDataAuditStatusEnum.AUDIT_STATUS_ADD_REJECT.getType().equals(mchntBase.getAuditStatus())
                    || BizDataAuditStatusEnum.AUDIT_STATUS_UPD_NOTCOMMIT.getType().equals(mchntBase.getAuditStatus()) || BizDataAuditStatusEnum.AUDIT_STATUS_ADD_NOTCOMMIT.getType().equals(mchntBase.getAuditStatus())
                    || BizDataStatusEnum.STATUS_DRAFT.getType().equals(mchntBase.getMchntStatus()))) {
                //新增、修改拒绝时查询临时表数据
                entity = bMchntAcctInfoService.mchntSettleInfoQuery(instId, req, bompMchntQueryService, genMerOrder(instId), BompQueryTypeEnum.TEMP);
                queryType = "0";
            } else if (PageOptFlagEnum.OPT_FLAG_CHECK.getType().equals(optFlag) || PageOptFlagEnum.OPT_FLAG_CHECK_VIEW.getType().equals(optFlag)) {
                entity = bMchntAcctInfoService.mchntSettleInfoQuery(instId, req, bompMchntQueryService, genMerOrder(instId), BompQueryTypeEnum.TEMP);
                queryType = "0";
                //TODO 审核对比功能屏蔽
/*
                if (BizDataAuditStatusEnum.AUDIT_STATUS_UPD_CHECKING.getType().equals(mchntBase.getAuditStatus())) {
                    MchntSettleAcctInfoQueryResponse entityReal = bMchntAcctInfoService.mchntSettleInfoQuery(instId, req, bompMchntQueryService, genMerOrder(instId), BompQueryTypeEnum.REAL);
                    MchntSettleInfoManageVO voReal = new MchntSettleInfoManageVO();
                    getMchntSettleVO(entityReal, voReal);
                    voReal.setInstId(instId);
                    voReal.setMchntNo(mchntNo);
                    vo = new MchntSettleInfoManageVO();
                    getMchntSettleVO(entity, vo);
                    vo.setInstId(instId);
                    vo.setOptFlag(optFlag);
                    List<LabelValueBean> compareBeans = CommonUtils.compareData(vo, voReal, MchntSettleInfoManageVO.class);
                    for (LabelValueBean bean : compareBeans) {
                        if (Common.isNotBlank(bean.getValue())) {
                            String beanVal = bean.getValue();
                            if ("realSettleFlag".equals(bean.getElabel())) {
                                beanVal = bean.getValue() + "-" + EnumUtils.getEnumDescriotionByValue(bean.getValue(), IgasYesOrNoEnum.class, "getType", "getDesc");
                            } else if ("mchntSettleMode".equals(bean.getElabel())) {
                                beanVal = bean.getValue() + "-" + EnumUtils.getEnumDescriotionByValue(bean.getValue(), MchntSettleModeEnum.class, "getType", "getDesc");
                            } else if ("cashWithdrawalFlag".equals(bean.getElabel())) {
                                beanVal = bean.getValue() + "-" + EnumUtils.getEnumDescriotionByValue(bean.getValue(), IgasYesOrNoEnum.class, "getType", "getDesc");
                            } else if ("feeInputMode".equals(bean.getElabel())) {
                                beanVal = bean.getValue() + "-" + EnumUtils.getEnumDescriotionByValue(bean.getValue(), FeeInputModeEnum.class, "getType", "getDesc");
                            }
                            bean.setValue(beanVal);
                        }
                    }
                    result.put("compareBeans", JSON.toJSONString(compareBeans));

                    List<LabelValueBean> compareSettleAcctBeans = CommonUtils.compareData(vo.getSettleAcctInfo(), voReal.getSettleAcctInfo(), SettleAcctInfoVO.class);
                    for (LabelValueBean bean : compareSettleAcctBeans) {
                        if (Common.isNotBlank(bean.getValue())) {
                            String beanVal = bean.getValue();
                            if ("settleAcctType".equals(bean.getElabel())) {
                                beanVal = bean.getValue() + "-" + EnumUtils.getEnumDescriotionByValue(bean.getValue(), SettleAccTypeEnum.class, "getType", "getDesc");
                            } else if ("settleType".equals(bean.getElabel())) {
                                beanVal = bean.getValue() + "-" + EnumUtils.getEnumDescriotionByValue(bean.getValue(), BompSettleTypeEnum.class, "getType", "getTypeDesc");
                            } */
/*else if ("settleImage".equals(bean.getElabel())) {//图像处理
                                List<LabelValueBean> compareSettleAcctImgBeans = CommonUtils.compareData(vo.getSettleAcctInfo().getSettleImage(), voReal.getSettleAcctInfo().getSettleImage(), ImageInfoVO.class);
                              result.put("compareSettleAcctImgBeans", JSON.toJSONString(compareSettleAcctImgBeans));
                            }*//*

                            bean.setValue(beanVal);
                        }
                    }
                    result.put("compareSettleAcctBeans", JSON.toJSONString(compareSettleAcctBeans));

                    List<LabelValueBean> compareFeeSettleAcctBeans = CommonUtils.compareData(vo.getFeeAcctInfo(), voReal.getFeeAcctInfo(), SettleAcctInfoVO.class);
                    for (int i = 0; i < compareFeeSettleAcctBeans.size(); i++) {
                        LabelValueBean bean = compareFeeSettleAcctBeans.get(i);
                        if (Common.isNotBlank(bean.getValue())) {
                            String beanVal = bean.getValue();
                            if ("settleAcctType".equals(bean.getElabel())) {
                                beanVal = bean.getValue() + "-" + EnumUtils.getEnumDescriotionByValue(bean.getValue(), SettleAccTypeEnum.class, "getType", "getDesc");
                            } else if ("settleType".equals(bean.getElabel())) {
                                beanVal = bean.getValue() + "-" + EnumUtils.getEnumDescriotionByValue(bean.getValue(), BompSettleTypeEnum.class, "getType", "getTypeDesc");
                                bean.setElabel("feeSettleType");
                                LabelValueBean beanExt = new LabelValueBean();
                                BeanUtils.copyProperties(bean, beanExt);
                                beanExt.setElabel("feeSettleType");
                                compareFeeSettleAcctBeans.add(beanExt);
                            } else if ("settleCycle".equals(bean.getElabel())) {
                                LabelValueBean beanExt = new LabelValueBean();
                                BeanUtils.copyProperties(bean, beanExt);
                                beanExt.setElabel("feeSettleCycle");
                                compareFeeSettleAcctBeans.add(beanExt);
                            } else if ("settleAcctNo".equals(bean.getElabel())) {
                                LabelValueBean beanExt = new LabelValueBean();
                                BeanUtils.copyProperties(bean, beanExt);
                                beanExt.setElabel("feeSettleAcctNo");
                                compareFeeSettleAcctBeans.add(beanExt);
                            } else if ("settleImage".equals(bean.getElabel())) {//图像处理
                                */
/*List<LabelValueBean> compareFeeSettleAcctImgBeans = CommonUtils.compareData(vo.getFeeAcctInfo().getSettleImagelist(), voReal.getFeeAcctInfo().getSettleImagelist(), ImageInfoVO.class);
                              result.put("compareFeeSettleAcctImgBeans", JSON.toJSONString(compareFeeSettleAcctImgBeans));*//*

                            }
                            bean.setValue(beanVal);
                        }
                    }

                    result.put("compareFeeSettleAcctBeans", JSON.toJSONString(compareFeeSettleAcctBeans));

                    List<LabelValueBean> compareCashWithDrawBeans = CommonUtils.compareData(vo.getCashWithdrawalFeeInfo(), voReal.getCashWithdrawalFeeInfo(), CashWithdrawalFeeInfoVO.class);
                    for (LabelValueBean bean : compareFeeSettleAcctBeans) {
                        if (Common.isNotBlank(bean.getValue())) {
                            String beanVal = bean.getValue();
                            if ("feeType".equals(bean.getElabel())) {
                                beanVal = bean.getValue() + "-" + EnumUtils.getEnumDescriotionByValue(bean.getValue(), SettleAccTypeEnum.class, "getType", "getDesc");
                            } else if ("feeInputMode".equals(bean.getElabel())) {
                                beanVal = bean.getValue() + "-" + EnumUtils.getEnumDescriotionByValue(bean.getValue(), FeeInputModeEnum.class, "getType", "getDesc");
                            }
                            bean.setValue(beanVal);
                        }
                    }
                    result.put("compareCashWithDrawBeans", JSON.toJSONString(compareCashWithDrawBeans));
                }
*/
                ParamQueryRequest cashwithdrawalflag = new ParamQueryRequest();
                cashwithdrawalflag.setUserId(user.getId());
                cashwithdrawalflag.setParamType(BusinessContainer.MCMP_TO_BOMP_PARAM_TYPE); //待定
                cashwithdrawalflag.setParamKey(ParamQueryKeyEnum.CASH_WITHDRAWAL_FLAG.getType()); //待定
                ParamQueryResponse paramResp = paramQuery(instId, cashwithdrawalflag, genMerOrder(instId));
                if (Common.isNotBlank(paramResp)) {
                    List<SysParamBean> sysParamList = paramResp.getSysParamList();
                    if (CollectionUtils.isNotEmpty(sysParamList)) {
                        result.put("cashwithdrawalflag", sysParamList.get(0).getParamValue());
                    }
                }

            } else {
                //查询正式表数据
                entity = bMchntAcctInfoService.mchntSettleInfoQuery(instId, req, bompMchntQueryService, genMerOrder(instId), BompQueryTypeEnum.REAL);
                queryType = "1";
            }
            vo = new MchntSettleInfoManageVO();
            getMchntSettleVO(entity, vo);
            vo.setInstId(instId);

            //查询是否支持D0
            MchntD0QueryRequest reqD0 = new MchntD0QueryRequest();
            reqD0.setMchntNo(mchntNo);
            reqD0.setUserId(user.getId());
            MchntD0QueryResponse rspD0 = mchntD0Query(instId, reqD0, bompMchntPublicDealService, genMerOrder(instId));
            if (Common.isNotBlank(rspD0)) {
                result.put("d0Flag", rspD0.getD0Flag());
                result.put("innerChannelD0Flag", rspD0.getInnerChannelD0Flag());
                result.put("cashDrawFlag", rspD0.getCashDrawFlag());
            }

            //查询是否开通提现

        } else {
            log.error("不支持的操作");
            throw new RedpException("不支持的操作");
        }
        List<LabelValueBean> yesOrNo = Lists.newArrayList();
        yesOrNo.add(new LabelValueBean("是", IgasYesOrNoEnum.Yes.getType()));
        yesOrNo.add(new LabelValueBean("否", IgasYesOrNoEnum.No.getType()));
        result.put("yesOrNo", yesOrNo);
        List<LabelValueBean> settleMode = Lists.newArrayList();
        /*settleMode.add(new LabelValueBean("轧差清算",MchntSettleModeEnum.MERGE_BUSINESS_SETTLE.getType()));
        settleMode.add(new LabelValueBean("收支两线",MchntSettleModeEnum.MERGE_BUSINESS_TWOLINE.getType()));
        result.put("settleMode",settleMode);*/
//        result.put("chainMchntNo",mchntBase.getc);

        vo.setOptFlag(optFlag);
        result.put("entity", vo);
        result.put("queryType", queryType);
        return result;
    }

    public MchntD0QueryResponse mchntD0Query(String instId, MchntD0QueryRequest req, BompMchntPublicDealService bompMchntPublicDealService, String traceNo) throws RedpException {
        req.setHeader(CommonUtils.packageBompHeader(traceNo, BompTxnNumEnum.mchntD0Query.getType(), instId, null));

        try {
            log.info("法人行[" + instId + "],用户标识[" + req.getUserId() + "],商户号[" + req.getMchntNo() + "]" + BompTxnNumEnum.mchntD0Query.getDesc() + "交易请求报文：" + JSON.toJSONString(req));
            Result<MchntD0QueryResponse> response = bompMchntPublicDealService.mchntD0Query(req);
            log.info("法人行[" + instId + "],用户标识[" + req.getUserId() + "],商户号[" + req.getMchntNo() + "]" + BompTxnNumEnum.mchntD0Query.getDesc() + "交易返回报文：" + JSON.toJSONString(response));
            if (response.isSuccess()) {
                MchntD0QueryResponse resp = response.getResult();
                // 返回码：00000000-进件成功，其他均视为失败
                if (BusinessContainer.BSPS_SUCCESS.equals(resp.getRespCode())) {
                    log.info("法人行[" + instId + "],用户标识[" + req.getUserId() + "],商户号[" + req.getMchntNo() + "]" + BompTxnNumEnum.mchntD0Query.getDesc() + "交易成功");
                    return resp;
                } else {
                    log.error("法人行[" + instId + "],用户标识[" + req.getUserId() + "],商户号[" + req.getMchntNo() + "]" + BompTxnNumEnum.mchntD0Query.getDesc() + "交易失败");
                    return null;
                }
            } else {
                log.error("法人行[" + instId + "],用户标识[" + req.getUserId() + "],商户号[" + req.getMchntNo() + "]" + BompTxnNumEnum.mchntD0Query.getDesc() + "交易没有获得返回信息");
                return null;
            }
        } catch (Exception e) {
            // TODO: handle exception
            log.error("法人行[" + instId + "],用户标识[" + req.getUserId() + "],商户号[" + req.getMchntNo() + "]" + BompTxnNumEnum.mchntD0Query.getDesc() + "交易出现异常，异常信息：" + e.getMessage(), e);
            throw new RedpException("法人行[" + instId + "],用户标识[" + req.getUserId() + "],商户号[" + req.getMchntNo() + "]" + BompTxnNumEnum.mchntD0Query.getDesc() + "交易出现异常，异常信息：" + e.getMessage());
        }
    }

    /**
     * 从 MchntSettleAcctInfoQueryResponse 转换成 MchntSettleInfoManageVO
     *
     * @param entity
     * @param vo
     */
    public void getMchntSettleVO(MchntSettleAcctInfoQueryResponse entity, MchntSettleInfoManageVO vo) {
        BeanUtils.copyProperties(entity, vo);
        //取出结算账户
        List<SettleAcctInfoBean> accts = entity.getSettleAcctInfoList();
        //转换区分结算账户、手续费结算账户
        if (Common.isNotBlank(accts) && accts.size() > 0) {
            List<SettleAcctInfoVO> settles = Lists.newArrayList();
            Iterator<SettleAcctInfoBean> it = accts.iterator();
            while (it.hasNext()) {
                SettleAcctInfoBean acct = it.next();
                SettleAcctInfoVO settle = new SettleAcctInfoVO();
                BeanUtils.copyProperties(acct, settle);
                List<SignImageInfoBean> settleImageInfoList = acct.getSettleImageInfoList();
                if (CollectionUtils.isNotEmpty(acct.getSettleImageInfoList())) {
                    List<ImageInfoVO> settleImagelist = new ArrayList<>();
                    for (SignImageInfoBean settleacctinfobean : acct.getSettleImageInfoList()) {
                        ImageInfoVO settleImg = new ImageInfoVO();
                        BeanUtils.copyProperties(settleacctinfobean, settleImg);
                        settleImagelist.add(settleImg);
                    }
                    settle.setSettleImagelist(settleImagelist);
                }
                if (MchntFundTypeEnum.MCHNT_SETTLE_NET.getType().equals(acct.getFundType())) {


                    vo.setSettleAcctInfo(settle);
                } else {
                    vo.setFeeAcctInfo(settle);
                }
                settles.add(settle);
            }
            vo.setSettleAcctInfoList(settles);
        }
        /** 增加 提现费率转换 **/
        if ("Y".equals(entity.getCashWithdrawalFlag()) && Common.isNotBlank(entity.getCashWithdrawalFeeInfoBean())) {
            CashWithdrawalFeeInfoVO cashWithdrawalFeeInfo = new CashWithdrawalFeeInfoVO();
            BeanUtils.copyProperties(entity.getCashWithdrawalFeeInfoBean(), cashWithdrawalFeeInfo);
        }
    }

    @Override
    public OperationResult mchntAcctSave(MchntSettleInfoManageVO entity) throws RedpException {
        UpmpUserInfoVO user = CommonUtils.getCurrentUser(upmpSysParamService);
        CommonUtils.validateUserInst(entity.getInstId(), user);

        if (PageOptFlagEnum.OPT_FLAG_ADD.getType().equals(entity.getOptFlag())
                || PageOptFlagEnum.OPT_FLAG_UPDATE.getType().equals(entity.getOptFlag())) {
            //新增操作先查一次看之前是否已经保存，如果已经保存则修改
            if (PageOptFlagEnum.OPT_FLAG_ADD.getType().equals(entity.getOptFlag())) {
                MchntSettleAcctInfoQueryRequest reqQry = new MchntSettleAcctInfoQueryRequest();
                reqQry.setMchntNo(entity.getMchntNo());
                reqQry.setUserId(user.getId());
                MchntSettleAcctInfoQueryResponse resp = bMchntAcctInfoService.mchntSettleInfoQuery(entity.getInstId(), reqQry, bompMchntQueryService, genMerOrder(entity.getInstId()), BompQueryTypeEnum.REAL);
                if (Common.isNotBlank(resp)) {//如果应答非空则认为是修改
                    entity.setOptFlag(PageOptFlagEnum.OPT_FLAG_UPDATE.getType());
                }
            }
            MchntSettleInfoManageRequest req = new MchntSettleInfoManageRequest();
            req.setUserId(user.getId());
            BeanUtils.copyProperties(entity, req);
            List<SettleAcctInfoBean> bompAccts = Lists.newArrayList();
            List<SettleAcctInfoVO> accts = entity.getSettleAcctInfoList();

            MchntBaseInfoQueryResponse mchntBaseTmp = mchntBaseInfoQuery(entity.getInstId(), user, genMerOrder(entity.getInstId()), entity.getMchntNo(), "", BompQueryTypeEnum.TEMP, bompMchntQueryService);
            MchntSignInfoQueryRequest reqSign = new MchntSignInfoQueryRequest();
            reqSign.setUserId(user.getId());
            reqSign.setMchntNo(entity.getMchntNo());
            MchntSignInfoQueryResponse respSign = bMchntSignInfoService.mchntSignInfoQuery(entity.getInstId(), reqSign, bompMchntQueryService, genMerOrder(entity.getInstId()), BompQueryTypeEnum.TEMP);
            MchntImageInfoQueryRequest reqImg = new MchntImageInfoQueryRequest();
            reqImg.setUserId(user.getId());
            reqImg.setMchntNo(entity.getMchntNo());
            MchntImageInfoQueryResponse respImg = bMchntImageInfoService.mchntImageInfoQuery(entity.getInstId(), reqImg, bompMchntQueryService, genMerOrder(entity.getInstId()), BompQueryTypeEnum.TEMP);
            long fundManageImg = 0l;
            if (Common.isNotBlank(respImg) && CollectionUtils.isNotEmpty(respImg.getMchntImageInfoList())) {
                fundManageImg = respImg.getMchntImageInfoList().stream().filter(img -> img.getImageType().equals(BompImageTypeEnum.FUND_MANAGE.getImageType())).count();
            }

            Iterator<SettleAcctInfoVO> it = accts.iterator();
            while (it.hasNext()) {
                SettleAcctInfoVO acct = it.next();
                //《银行卡收到管理办法》 第29条关于成员行收单业务商户结算账户的相关规定
                //（一）当商户性质为企业时，如商户无法提供指定的、与其存在合法资金管理关系的收单结算账户，则系统内登记的收单结算账户必须为对公户，且户名与商户中文名称保存一致；
                //                       如商户可以提供指定的、与其存在合法资金管理关系的收单结算账户，则系统内登记的收单结算账户必须为对公户，且需提交该收单结算账户与商户存在合法资金管理关系的证明材料；
                //（二）当商户性质为个体工商户，且系统内登记的收单结算账户为对公户时，户名必须与商户中文名称保持一致；
                //        当收单结算账户为个人结算账户时，收单结算账户须为该个体工商户个人同名结算账户
                //（三）当商户性质为小微商户时，收单结算账户须与系统内登记的商户信息保持一致
                /*if(!MchntTypeEnum.SMALL_MICRO_MCHNT.getType().equals(mchntBaseTmp.getMchntBaseInfo().getMchntType())
                        &&!MchntEnterRegisterTypeEnum.INDIVIDUAL.getType().equals(respSign.getBusinessLicenceInfo().getEnterRegisterType())){
                    if(fundManageImg == 0l){
                        *//*if(SettleAccTypeEnum.INNER_PUBLIC_ACCOUNT.getType().equals(acct.getSettleAcctType())
                                ||SettleAccTypeEnum.OTHER_PUBLIC_ACCOUNT.getType().equals(acct.getSettleAcctType())){
                            if(!mchntBaseTmp.getMchntBaseInfo().getMchntName().equals(acct.getSettleAcctName())){
                                //如果户名与商户中文名称不一致,检查是否上传资金存管证明
                                return OperationResult.buildFailureResult("请先上传账户"+acct.getSettleAcctNo()+"的资金管理关系证明照");
                            }
                        }*//*
                    }els51
                        if(!SettleAccTypeEnum.INNER_PUBLIC_ACCOUNT.getType().equals(acct.getSettleAcctType())
                                &&!SettleAccTypeEnum.OTHER_PUBLIC_ACCOUNT.getType().equals(acct.getSettleAcctType())){
                            //如商户可以提供指定的、与其存在合法资金管理关系的收单结算账户，则系统内登记的收单结算账户必须为对公户，且需提交该收单结算账户与商户存在合法资金管理关系的证明材料
                            return OperationResult.buildFailureResult("商户注册类型为企业时，账户"+acct.getSettleAcctNo()+"必须为对公户！");
                        }
                    }
                }else if(MchntEnterRegisterTypeEnum.INDIVIDUAL.getType().equals(respSign.getBusinessLicenceInfo().getEnterRegisterType())){
                    if(SettleAccTypeEnum.INNER_PUBLIC_ACCOUNT.getType().equals(acct.getSettleAcctType())
                            ||SettleAccTypeEnum.OTHER_PUBLIC_ACCOUNT.getType().equals(acct.getSettleAcctType())){
                        if(!mchntBaseTmp.getMchntBaseInfo().getMchntName().equals(acct.getSettleAcctName())){
                            //当商户性质为个体工商户，且系统内登记的收单结算账户为对公户时，户名须与商户中文名称保持一致；
                            return OperationResult.buildFailureResult("当收单结算账户为个人结算账户时，收单结算账户"+acct.getSettleAcctNo()+"户名须与商户中文名称保持一致");
                        }
                    }else{
                        if(!respSign.getMchntArtifInfo().getArtifName().equals(acct.getSettleAcctName())){
                            //当收单结算账户为个人结算账户时，收单结算账户须为该个体工商户个人同名结算账户
                            return OperationResult.buildFailureResult("当收单结算账户为个人结算账户时，收单结算账户"+acct.getSettleAcctNo()+"须为该个体工商户个人同名结算账户");
                        }
                    }
                }*/

                SettleAcctInfoBean bompAcct = new SettleAcctInfoBean();
                BeanUtils.copyProperties(acct, bompAcct);
                SignImageInfoBean bompImg = new SignImageInfoBean();
                List<ImageInfoVO> settleImagelist = acct.getSettleImagelist();
                List<SignImageInfoBean> settleImageInfoList = new ArrayList<>();
                for (ImageInfoVO imageinfovo : settleImagelist) {
                    SignImageInfoBean signimageinfobean = new SignImageInfoBean();
                    BeanUtils.copyProperties(imageinfovo, signimageinfobean);
                    settleImageInfoList.add(signimageinfobean);
                }
                bompAcct.setSettleImageInfoList(settleImageInfoList);
                bompAccts.add(bompAcct);
                List<ImageInfoVO> settleImagelist1 = acct.getSettleImagelist();
            }
            req.setSettleAcctInfoBeanList(bompAccts);
            if (PageOptFlagEnum.OPT_FLAG_ADD.getType().equals(entity.getOptFlag())) {
                req.setCashWithdrawalFlag(IgasYesOrNoEnum.No.getType());
                req.setRealSettleFlag(IgasYesOrNoEnum.No.getType());
            } else {
                //查询基本信息正式表数据校验商户状态是否锁定
                MchntBaseInfoQueryResponse mchntBase = mchntBaseInfoQuery(entity.getInstId(), user, genMerOrder(entity.getInstId()), entity.getMchntNo(), "", BompQueryTypeEnum.REAL, bompMchntQueryService);
                if (Common.isBlank(mchntBase)) {
                    throw new RedpException("商户号[" + entity.getMchntNo() + "]没有查询到对应的商户信息");
                }
                if (BizDataStatusEnum.STATUS_DRAFT.getType().equals(mchntBase.getMchntStatus())) {
                    if (CollectionUtils.isEmpty(accts)) {//如果是草稿且确实没有数据时的修改提交，则还是认为是新增
                        entity.setOptFlag(PageOptFlagEnum.OPT_FLAG_ADD.getType());
                        return mchntAcctSave(entity);
                    } else {
                        req.setCashWithdrawalFlag(IgasYesOrNoEnum.No.getType());
                        req.setRealSettleFlag(IgasYesOrNoEnum.No.getType());
                    }
                }

                CashWithdrawalFeeInfoBean bompFeeInfo = new CashWithdrawalFeeInfoBean();
                if (Common.isNotBlank(entity.getCashWithdrawalFeeInfo())) {
                    BeanUtils.copyProperties(entity.getCashWithdrawalFeeInfo(), bompFeeInfo);
                }
                req.setCashWithdrawalFeeInfoBean(bompFeeInfo);
            }

            return mchntAcctSave(entity.getInstId(), req, genMerOrder(entity.getInstId()), entity.getOptFlag());

        } else {
            Map<String, Object> result = Maps.newHashMap();
            result.put("instId", entity.getInstId());
            result.put("mchntNo", entity.getMchntNo());
            result.put("optFlag", entity.getOptFlag());
            return OperationResult.buildSuccessResult(BompTxnNumEnum.mchntSettleInfoManage.getDesc() + "交易成功", result);
        }
    }

    public OperationResult mchntAcctSave(String instId, MchntSettleInfoManageRequest req,
                                         String traceNo, String optFlag) throws RedpException {
        UpmpUserInfoVO user = CommonUtils.getCurrentUser(upmpSysParamService);
        /**商户写死必须审核*/
        req.setHeader(CommonUtils.packageBompHeader(traceNo, BompTxnNumEnum.mchntSettleInfoManage.getType(), instId, null));
        if (PageOptFlagEnum.OPT_FLAG_ADD.getType().equals(optFlag)) {
            req.setOprType(BompManageOprTypeEnum.CREATE.getType());
            UpmpPrivilegeCheck privilegeCheck = upmpPrivilegeCheckService.getPrivilegeCheckByPrivilegeCode(instId,
                    oprBtnNamePrefix + BusinessContainer.AUTH_PRIVILEGE_CODE_SPLIT + PageOptFlagEnum.OPT_FLAG_ADD.getDesc());
            if (null != privilegeCheck && BusinessContainer.YES.equals(privilegeCheck.getChecked())) {
                req.setChecked(BompAuditFlagEnum.CHECK.getType());
                req.setOprMenuId(oprMenuId);
                req.setOprMenuName(oprMenuName);
                req.setWebNextUrl(webNextUrl);
                //设置主记录是否需要显示
                req.setMasterShowFlag(IgasYesOrNoEnum.No.getType());

            } else {
                /*req.setChecked(BompAuditFlagEnum.NO_CHECK.getType());
                //设置主记录是否需要显示
                req.setMasterShowFlag(IgasYesOrNoEnum.No.getType());*/
                req.setChecked(BompAuditFlagEnum.CHECK.getType());
                req.setOprMenuId(oprMenuId);
                req.setOprMenuName(oprMenuName);
                req.setWebNextUrl(webNextUrl);
                //设置主记录是否需要显示
                req.setMasterShowFlag(IgasYesOrNoEnum.No.getType());
            }
        } else if (PageOptFlagEnum.OPT_FLAG_UPDATE.getType().equals(optFlag)) {

            req.setOprType(BompManageOprTypeEnum.MODIFY.getType());
            UpmpPrivilegeCheck privilegeCheck = upmpPrivilegeCheckService.getPrivilegeCheckByPrivilegeCode(instId,
                    oprBtnNamePrefix + BusinessContainer.AUTH_PRIVILEGE_CODE_SPLIT + PageOptFlagEnum.OPT_FLAG_UPDATE.getDesc());

            if (null != privilegeCheck && BusinessContainer.YES.equals(privilegeCheck.getChecked())) {
                req.setChecked(BompAuditFlagEnum.CHECK.getType());
                req.setOprMenuId(oprMenuId);
                req.setOprMenuName(oprMenuName);
                req.setWebNextUrl(webNextUrl);
                //设置主记录是否需要显示
                req.setMasterShowFlag(IgasYesOrNoEnum.No.getType());

            } else {
                    /*req.setChecked(BompAuditFlagEnum.NO_CHECK.getType());
                    //设置主记录是否需要显示
                    req.setMasterShowFlag(IgasYesOrNoEnum.No.getType());*/
                req.setChecked(BompAuditFlagEnum.CHECK.getType());
                req.setOprMenuId(oprMenuId);
                req.setOprMenuName(oprMenuName);
                req.setWebNextUrl(webNextUrl);
                //设置主记录是否需要显示
                req.setMasterShowFlag(IgasYesOrNoEnum.No.getType());
            }
        } else {
            throw new RedpException("不支持的操作");
        }

        log.info("商户编号为：" + req.getMchntNo() + "的商户，" + BompTxnNumEnum.mchntSettleInfoManage.getDesc() + "请求报文：" + JSON.toJSONString(req));

        Map<String, Object> result = Maps.newHashMap();
        try {
            Result<MchntSettleInfoManageResponse> response = bompMchntManageService.mchntSettleInfoManage(req);
            log.info("商户编号为：" + req.getMchntNo() + "的商户，" + BompTxnNumEnum.mchntSettleInfoManage.getDesc() + "返回报文：" + JSON.toJSONString(response));
            if (response.isSuccess()) {
                MchntSettleInfoManageResponse resp = response.getResult();
                // 返回码：00-进件成功，其他均视为失败
                if (BusinessContainer.BSPS_SUCCESS.equals(resp.getRespCode())) {
                    result.put("respCode", resp.getRespCode());
                    result.put("respMsg", resp.getRespDesc());

                    result.put("instId", instId);
                    result.put("mchntNo", req.getMchntNo());
                    result.put("optFlag", optFlag);
                    log.info("商户编号为：" + req.getMchntNo() + "的商户，" + BompTxnNumEnum.mchntSettleInfoManage.getDesc() + "成功");
                    return OperationResult.buildSuccessResult(BompTxnNumEnum.mchntSettleInfoManage.getDesc() + "成功", result);
                } else {

                    if (resp.getRespCode().equals(RespCodeEnum.ACCT_NO_REPEAT.getRespCode()) || resp.getRespCode().equals(RespCodeEnum.NOT_TO_ALLOW_WITHDRAWAL_AND_DO.getRespCode()) || resp.getRespCode().equals(RespCodeEnum.NOT_ALLOW_D0_WITHDRAWAL.getRespCode()) || resp.getRespCode().equals(RespCodeEnum.NOT_ALLOW_D0_BY_INST.getRespCode()) || resp.getRespCode().equals(RespCodeEnum.NOT_ALLOW_TO_SET_D0_D1_OF_FEE.getRespCode()) || resp.getRespCode().equals("ES000096")) {
                        return OperationResult.buildFailureResult(resp.getRespDesc(), result);
                    }
                    result.put("respCode", resp.getRespCode());
                    result.put("respMsg", resp.getRespDesc());
                    return OperationResult.buildFailureResult(BompTxnNumEnum.mchntSettleInfoManage.getDesc() + "失败", result);
                }
            } else {
                result.put("resCode", BusinessContainer.ERROR);
                result.put("resMsg", BompTxnNumEnum.mchntSettleInfoManage.getDesc() + "没有获得返回报文");
                log.error("商户编号为：" + req.getMchntNo() + "的商户，" + BompTxnNumEnum.mchntSettleInfoManage.getDesc() + "没有获得返回信息");
                return OperationResult.buildFailureResult(BompTxnNumEnum.mchntSettleInfoManage.getDesc() + "失败", result);
            }
        } catch (Exception e) {
            // TODO: handle exception
            result.put("resCode", BusinessContainer.ERROR);
            result.put("resMsg", e.getMessage());
            log.error("商户编号为：" + req.getMchntNo() + "的商户，" + BompTxnNumEnum.mchntSettleInfoManage.getDesc() + "出现异常，异常信息：" + e.getMessage(), e);
            return OperationResult.buildFailureResult(BompTxnNumEnum.mchntSettleInfoManage.getDesc() + "失败", result);
        }
    }

    @Override
    public Map<String, Object> mchntProdShow(String instId, String mchntNo, String mchntName, String optFlag) throws RedpException {
        HashMap<String, Object> result = new HashMap<>();
        UpmpUserInfoVO user = CommonUtils.getCurrentUser(upmpSysParamService);
        String flag = optFlag;
        CommonUtils.validateUserInst(instId, user);
        if (PageOptFlagEnum.OPT_FLAG_ADD.getType().equals(optFlag)) {

            List<ProdInfoBean> prodList = bMchntProdInfoService.getProdInfoList(instId, user, bompPublicQueryService, genMerOrder(instId));
            List<BaseProdInfoBean> baseProdList = bMchntProdInfoService.getBaseProdInfoList(instId, user, bompPublicQueryService, genMerOrder(instId));
            ProdInfoBean prodInfoBean = new ProdInfoBean();
            prodInfoBean.setProdCode(BusinessContainer.CUSTOM_PROD_CODE);
            prodInfoBean.setProdDesc(BusinessContainer.CUSTOM_PROD_NAME);
            prodInfoBean.setProdName(BusinessContainer.CUSTOM_PROD_NAME);
            Iterator<BaseProdInfoBean> iterator = baseProdList.iterator();
            while (iterator.hasNext()){
                BaseProdInfoBean next = iterator.next();
                if(BaseProdCodeEnum.COMMOM_PROD.getType().equals(next.getBaseProdCode())){
                    iterator.remove();
                    break;
                }
            }
            prodInfoBean.setBaseProdInfoList(baseProdList);
            if(CollectionUtils.isEmpty(prodList)){
                prodList=Lists.newArrayList();
            }
            prodList.add(prodInfoBean);
            result.put("prodList", prodList);

        } else if (PageOptFlagEnum.OPT_FLAG_UPDATE.getType().equals(optFlag)
                || PageOptFlagEnum.OPT_FLAG_USE.getType().equals(optFlag)
                || PageOptFlagEnum.OPT_FLAG_STOP.getType().equals(optFlag)
                || PageOptFlagEnum.OPT_FLAG_CANCEL.getType().equals(optFlag)
                || PageOptFlagEnum.OPT_FLAG_VIEW.getType().equals(optFlag)
                || PageOptFlagEnum.OPT_FLAG_CHECK.getType().equals(optFlag)
                || PageOptFlagEnum.OPT_FLAG_CHECK_VIEW.getType().equals(optFlag)) {

            //查询商户状态是否是新增退回、修改退回
            MchntBaseInfoQueryResponse mchntBase = mchntBaseInfoQuery(instId, user, genMerOrder(instId), mchntNo, mchntName, BompQueryTypeEnum.REAL, bompMchntQueryService);
            result.put("auditRefuseReason", Common.isBlank(mchntBase.getAuditRefuseReason())?"":mchntBase.getAuditRefuseReason().toString());
            if (Common.isBlank(mchntBase)) {
                throw new RedpException("商户号[" + mchntNo + "]没有查询到对应的商户信息");
            }

            if ((BizDataAuditStatusEnum.AUDIT_STATUS_UPD_CHECKING.getType().equals(mchntBase.getAuditStatus())
                    || BizDataAuditStatusEnum.AUDIT_STATUS_STOP_CHECKING.getType().equals(mchntBase.getAuditStatus())
                    || BizDataAuditStatusEnum.AUDIT_STATUS_USE_CHECKING.getType().equals(mchntBase.getAuditStatus())
                    || BizDataAuditStatusEnum.AUDIT_STATUS_CANCEL_CHECKING.getType().equals(mchntBase.getAuditStatus()))
                    && !PageOptFlagEnum.OPT_FLAG_VIEW.getType().equals(optFlag)
                    && !PageOptFlagEnum.OPT_FLAG_CHECK.getType().equals(optFlag)
                    && !PageOptFlagEnum.OPT_FLAG_CHECK_VIEW.getType().equals(optFlag)) {
                throw new RedpException("商户号[" + mchntNo + "]的商户信息已被审批流程锁定！");
            }
            if (BizDataAuditStatusEnum.AUDIT_STATUS_ADD_NOTCOMMIT.getType().equals(mchntBase.getAuditStatus())) {
                flag = "add";
            }

            List<MchntProdInfoBean> mchntProdList = Lists.newArrayList();
            List<MchntProdInfoBean> mchntProdRealList = Lists.newArrayList();
            if (PageOptFlagEnum.OPT_FLAG_UPDATE.getType().equals(optFlag)
                    && (BizDataAuditStatusEnum.AUDIT_STATUS_UPD_REJECT.getType().equals(mchntBase.getAuditStatus()) || BizDataAuditStatusEnum.AUDIT_STATUS_ADD_REJECT.getType().equals(mchntBase.getAuditStatus())
                    || BizDataAuditStatusEnum.AUDIT_STATUS_UPD_NOTCOMMIT.getType().equals(mchntBase.getAuditStatus()) || BizDataAuditStatusEnum.AUDIT_STATUS_ADD_NOTCOMMIT.getType().equals(mchntBase.getAuditStatus())
                    || BizDataStatusEnum.STATUS_DRAFT.getType().equals(mchntBase.getMchntStatus()))) {
                //新增、修改拒绝时查询临时表数据
                mchntProdList = bMchntProdInfoService.getMchntProdInfoList(instId, user, bompMchntQueryService, genMerOrder(instId), mchntNo, BompQueryTypeEnum.TEMP);
            } else
                if (PageOptFlagEnum.OPT_FLAG_CHECK.getType().equals(optFlag) || PageOptFlagEnum.OPT_FLAG_CHECK_VIEW.getType().equals(optFlag)) {
                mchntProdList = bMchntProdInfoService.getMchntProdInfoList(instId, user, bompMchntQueryService, genMerOrder(instId), mchntNo, BompQueryTypeEnum.TEMP);
                //TODO 审核对比功能屏蔽
                /*if (BizDataAuditStatusEnum.AUDIT_STATUS_UPD_CHECKING.getType().equals(mchntBase.getAuditStatus())) {
                    mchntProdRealList = bMchntProdInfoService.getMchntProdInfoList(instId, user, bompMchntQueryService, genMerOrder(instId), mchntNo, BompQueryTypeEnum.REAL);
                    CompareDataBean compareBeans = bMchntProdInfoService.getProdCompareFileById(mchntProdList, mchntProdRealList);
                    result.put("compareBeans", JSON.toJSONString(compareBeans));
                }*/
                MchntBaseInfoQueryResponse mchntBaseTmp = mchntBaseInfoQuery(instId, user, genMerOrder(instId), mchntNo, mchntName, BompQueryTypeEnum.TEMP, bompMchntQueryService);
                result.put("mchntStopReason", Common.isBlank(mchntBase.getMchntStopReason())?"":mchntBase.getMchntStopReason().toString());
                result.put("mchntCancelReason", Common.isBlank(mchntBase.getMchntCancelReason())?"":mchntBase.getMchntCancelReason().toString());
            } else {
                //查询正式表数据
                mchntProdList = bMchntProdInfoService.getMchntProdInfoList(instId, user, bompMchntQueryService, genMerOrder(instId), mchntNo, BompQueryTypeEnum.REAL);
            }

            String prodCode = "";
            String prodName = "";
            if (CollectionUtils.isNotEmpty(mchntProdList)) {
                MchntProdInfoBean mchntProd = mchntProdList.get(0);
                prodCode = mchntProd.getProdCode();
                prodName = mchntProd.getProdName();
                //判断是否自定义产品，如果自定义产品则加载未选中的基础产品
//                if(BusinessContainer.CUSTOM_PROD_CODE.equals(prodCode)){
                if (Common.isBlank(prodName)) {
                    prodName = BusinessContainer.CUSTOM_PROD_NAME;
                }
                mchntProdList.forEach(mProd -> mProd.setBaseProdPath(IgasYesOrNoEnum.Yes.getType()));

                List<BaseProdInfoBean> baseProdList = bMchntProdInfoService.getBaseProdInfoList(instId, user, bompPublicQueryService, genMerOrder(instId));

                Iterator<BaseProdInfoBean> iterator = baseProdList.iterator();
                while (iterator.hasNext()){
                    BaseProdInfoBean next = iterator.next();
                    if(BaseProdCodeEnum.COMMOM_PROD.getType().equals(next.getBaseProdCode())){
                        iterator.remove();
                        break;
                    }
                }

                if (!optFlag.equals("chk")) {
                    if (CollectionUtils.isNotEmpty(baseProdList)) {
                        final List<MchntProdInfoBean> mchntProdList1 = mchntProdList;
                        List<MchntProdInfoBean> prodFormBase = Lists.newArrayList();
                        //当已选的商户产品记录数小于基础产品记录数时，将商户未选的基础产品add到mchntProdList中
                        baseProdList.stream().filter(baseProdInfoBean ->
                                mchntProdList1.stream().noneMatch(mchntProd1 ->
                                        mchntProd1.getBaseProdCode().equals(baseProdInfoBean.getBaseProdCode())&&!BaseProdCodeEnum.COMMOM_PROD.getType().equals(baseProdInfoBean.getBaseProdCode()))).forEach(baseProd -> {
                            MchntProdInfoBean mchntProd2 = new MchntProdInfoBean();
                            mchntProd2.setBaseProdCode(baseProd.getBaseProdCode());
                            //此处需后台修改接口bean增加对应字段
                            mchntProd2.setBaseProdName(baseProd.getBaseProdName());
                            mchntProd2.setBaseProdDesc(baseProd.getBaseProdDesc());
                            mchntProd2.setProdCode(BusinessContainer.CUSTOM_PROD_CODE);
                            mchntProd2.setProdName(BusinessContainer.CUSTOM_PROD_NAME);
                            //此字段借用来标识是否选中
                            mchntProd2.setBaseProdPath(IgasYesOrNoEnum.No.getType());
                            prodFormBase.add(mchntProd2);
                        });
                        if (CollectionUtils.isNotEmpty(prodFormBase)) {
                            mchntProdList.addAll(prodFormBase);
                        }
                    }
                }

//                }
            } else {//商户没有配置产品
                if (PageOptFlagEnum.OPT_FLAG_UPDATE.getType().equals(optFlag) && BizDataStatusEnum.STATUS_DRAFT.getType().equals(mchntBase.getMchntStatus())) {//商户状态是草稿，进入新增流程
                    optFlag = PageOptFlagEnum.OPT_FLAG_ADD.getType();
                    return mchntProdShow(instId, mchntNo, mchntName, optFlag);
                }
            }

            result.put("prodCode", prodCode);
            result.put("prodName", prodName);
            result.put("prodList", mchntProdList);

        } else {
            log.error("不支持的操作");
            throw new RedpException("不支持的操作");
        }
        MchntBaseInfoQueryResponse mchntBase = mchntBaseInfoQuery(instId, user, genMerOrder(instId), mchntNo, mchntName, BompQueryTypeEnum.TEMP, bompMchntQueryService);
        result.put("mchntAttr", mchntBase.getMchntBaseInfo().getMchntAttr());
        result.put("optFlag", optFlag);
        result.put("flag", flag);
        result.put("instId", instId);
        result.put("mchntNo", mchntNo);
        return result;
    }

    @Override
    public OperationResult mchntProdSave(MchntProdManagerVO entity) throws RedpException {
        UpmpUserInfoVO user = CommonUtils.getCurrentUser(upmpSysParamService);
        CommonUtils.validateUserInst(entity.getInstId(), user);

        if (PageOptFlagEnum.OPT_FLAG_UPDATE.getType().equals(entity.getOptFlag())
                || PageOptFlagEnum.OPT_FLAG_ADD.getType().equals(entity.getOptFlag())
                || PageOptFlagEnum.OPT_FLAG_CHECK.getType().equals(entity.getOptFlag())
                || PageOptFlagEnum.OPT_FLAG_PASS.getType().equals(entity.getOptFlag())
                || PageOptFlagEnum.OPT_FLAG_REJECT.getType().equals(entity.getOptFlag())) {

            MchntProdInfoManageRequest req = new MchntProdInfoManageRequest();
            bMchntProdInfoService.getMchntProdManageFromVO(req, entity);
            req.setUserId(user.getId());
            String manageOprType = "";
            if (PageOptFlagEnum.OPT_FLAG_ADD.getType().equals(entity.getOptFlag())) {
                manageOprType = "11";
            } else if (PageOptFlagEnum.OPT_FLAG_UPDATE.getType().equals(entity.getOptFlag())) {
                manageOprType = "12";
            } else if (PageOptFlagEnum.OPT_FLAG_CHECK.getType().equals(entity.getOptFlag())
                    || PageOptFlagEnum.OPT_FLAG_PASS.getType().equals(entity.getOptFlag())
                    || PageOptFlagEnum.OPT_FLAG_REJECT.getType().equals(entity.getOptFlag())) {
                manageOprType = "03";
                if (PageOptFlagEnum.OPT_FLAG_PASS.getType().equals(entity.getOptFlag())) {
                    req.setCheckStatus("01");
                } else if (PageOptFlagEnum.OPT_FLAG_REJECT.getType().equals(entity.getOptFlag())) {
                    req.setCheckStatus("02");
                }
            }
            MchntBaseInfoQueryResponse mchntBase = mchntBaseInfoQuery(entity.getInstId(), user, genMerOrder(entity.getInstId()), entity.getMchntNo(), "", BompQueryTypeEnum.REAL, bompMchntQueryService);
            for (MchntBaseProdManagerVO mchntbaseprodmanagervo : entity.getMchntBaseProdList()) {
                if (mchntbaseprodmanagervo.getBaseProdCode().equals("07")) {
                    MchntProdInfoQueryResponse mchntProdResp;
                    MchntProdInfoQueryRequest mchntProdreq = new MchntProdInfoQueryRequest();
                    mchntProdreq.setUserId(user.getId());
                    mchntProdreq.setMchntNo(entity.getMchntNo());
                    mchntProdreq.setProdCode(entity.getProdCode());
                    mchntProdreq.setBaseProdCode("07");
                    mchntProdResp = bMchntProdInfoService.getMchntProdInfoDtl(entity.getInstId(), bompMchntQueryService, genMerOrder(entity.getInstId()), mchntProdreq, BompQueryTypeEnum.TEMP);
                    if (mchntProdResp == null || CollectionUtils.isEmpty(mchntProdResp.getMchntAuthCtrlInfoList()) && CollectionUtils.isEmpty(mchntProdResp.getMchntFeeInfoList()) && CollectionUtils.isEmpty(mchntProdResp.getMchntStageInfoList())) {
                        mchntProdResp = new MchntProdInfoQueryResponse();
                        ProdInfoQueryRequest prodInfoReq = new ProdInfoQueryRequest();
                        prodInfoReq.setProdCode(entity.getProdCode());
                        prodInfoReq.setBaseProdCode("07");
                        prodInfoReq.setProdType(BompProdTypeEnum.STANDARD_PROD.getType());
                        prodInfoReq.setUserId(user.getId());
                        ProdInfoQueryResponse prodInfoResp = bMchntProdInfoService.getProdInfo(entity.getInstId(), bompPublicQueryService, genMerOrder(entity.getInstId()), prodInfoReq);
                        bMchntProdInfoService.getMchntProdFromProd(prodInfoResp, mchntProdResp, "07");
                    }

                    if (CollectionUtils.isNotEmpty(mchntProdResp.getMchntAuthCtrlInfoList())) {
                        for (MchntAuthCtrlInfoBean mchntauthctrlinfobean : mchntProdResp.getMchntAuthCtrlInfoList()) {
                            if ((Common.isBlank(mchntProdResp.getWechatAppid()) && Common.isBlank(mchntProdResp.getWechatAppidKey())) && (mchntauthctrlinfobean.getTxnGroup().equals("P01PM002") || mchntauthctrlinfobean.getTxnGroup().equals("P04BS003") || mchntauthctrlinfobean.getTxnGroup().equals("P04PM002")) && mchntauthctrlinfobean.getBizType().equals("02")) {
                                return OperationResult.buildFailureResult("请配置07微信支付产品微信APP支付APPID和微信APP支付KEY");
                            }
                            if ((Common.isBlank(mchntProdResp.getWechatMiniAppid()) && Common.isBlank(mchntProdResp.getWechatAppidKey())) && (mchntauthctrlinfobean.getTxnGroup().equals("P01PM002") || mchntauthctrlinfobean.getTxnGroup().equals("P04BS003") || mchntauthctrlinfobean.getTxnGroup().equals("P04PM002")) && mchntauthctrlinfobean.getBizType().equals("01")) {
                                return OperationResult.buildFailureResult("请配置07微信支付产品微信小程序支付APPID和微信小程序支付KEY");
                            }
                        }

                    }
                }
            }
            OperationResult operationResult = bMchntProdInfoService.mchntProdSave(entity.getInstId(), req, bompMchntManageService, upmpPrivilegeCheckService, genMerOrder(entity.getInstId()), entity.getOptFlag(), manageOprType);

            if (operationResult.getCode().equals("100000") && PageOptFlagEnum.OPT_FLAG_PASS.getType().equals(entity.getOptFlag())) {
                if (BizDataAuditStatusEnum.AUDIT_STATUS_CANCEL_CHECKING.getType().equals(mchntBase.getAuditStatus())) {
                    operationResult.setCode("111111");
                }
                Map<String, Object> data = (Map<String, Object>) operationResult.getData();
                data.put("MchntName", mchntBase.getMchntBaseInfo().getMchntName());
                data.put("MchntNo", mchntBase.getMchntBaseInfo().getMchntNo());
                data.put("instId", entity.getInstId());
            }
            return operationResult;
        } else {
            MchntStatusManageRequest req = new MchntStatusManageRequest();
            req.setUserId(user.getId());
            BeanUtils.copyProperties(entity, req);
            if (PageOptFlagEnum.OPT_FLAG_STOP.getType().equals(entity.getOptFlag())) {
                req.setOprType("02");
            } else if (PageOptFlagEnum.OPT_FLAG_USE.getType().equals(entity.getOptFlag())) {
                req.setOprType("03");
            } else if (PageOptFlagEnum.OPT_FLAG_CANCEL.getType().equals(entity.getOptFlag())) {
                req.setOprType("01");
            }
            return mchntStatusManage(entity.getInstId(), req, bompMchntManageService, genMerOrder(entity.getInstId()), entity.getOptFlag());
        }
    }


    @Override
    public Map<String, Object> mchntProdDtlShow(MchntProdUnitedFeeVO entity, String view) throws RedpException {
        HashMap<String, Object> result = new HashMap<>();
        UpmpUserInfoVO user = CommonUtils.getCurrentUser(upmpSysParamService);
        String optFlag = entity.getOptFlag();
        String flag = entity.getOptFlag();
        if (Common.isNotBlank(view)) {
            result.put("view", view);
        }
        String Status = "N";
        String disabled = "true";
        CommonUtils.validateUserInst(entity.getInstId(), user);
        if (IgasYesOrNoEnum.Yes.getType().equals(entity.getUnitedFeeFlag())) {
            if (FeeInputModeEnum.MANUAL_FIX.getType().equals(entity.getFeeInputMode())) {
                entity.setFeeRate(null);
                entity.setFeeFixedAmt(entity.getFeeCappingAmt());
                entity.setFeeCappingAmt(null);
            } else if (FeeInputModeEnum.MANUAL_RATE_MAX.getType().equals(entity.getFeeInputMode())) {
                entity.setFeeRate(entity.getFeeRate());
                entity.setFeeFixedAmt(null);
                entity.setFeeCappingAmt(entity.getFeeCappingAmt());
            } else if (FeeInputModeEnum.MANUAL_RATE.getType().equals(entity.getFeeInputMode())) {
                entity.setFeeRate(entity.getFeeRate());
                entity.setFeeFixedAmt(null);
                entity.setFeeCappingAmt(null);
            }
        }

        MchntProdInfoQueryResponse mchntProdResp;

        //查询商户状态是否是新增退回、修改退回
        MchntBaseInfoQueryResponse mchntBase = mchntBaseInfoQuery(entity.getInstId(), user, genMerOrder(entity.getInstId()), entity.getMchntNo(), null, BompQueryTypeEnum.REAL, bompMchntQueryService);
        if (Common.isBlank(mchntBase)) {
            log.error("商户号[" + entity.getMchntNo() + "]没有查询到对应的商户信息");
            throw new RedpException("商户号[" + entity.getMchntNo() + "]没有查询到对应的商户信息");
        }

        result.put("mchntStatus", mchntBase.getMchntStatus());
        result.put("auditStatus", mchntBase.getAuditStatus());

        //查询系统参数获取当前法人行的微信、支付宝走银联还是网联
        ParamQueryRequest reqParam = new ParamQueryRequest();
        reqParam.setUserId(user.getId());

        //此处先写死
        result.put("wechatChannelId", "UPWX");
        result.put("alipayChannelId", "UPAL");

        UpmpSysParam defaultInst = upmpSysParamService.getById(UpmpConstant.DEAFULT_INST_PARAM_ID);
        Map<String, String> map = upmpSysParamService.findMapDataByPrimaryKey(BusinessContainer.SYS_TXN_GROUP_PARAM, defaultInst.getPrimaryValue(), null);
        if (PageOptFlagEnum.OPT_FLAG_ADD.getType().equals(entity.getOptFlag())) {
            MchntProdInfoQueryRequest req = new MchntProdInfoQueryRequest();
            req.setUserId(user.getId());
            req.setMchntNo(entity.getMchntNo());
            req.setProdCode(entity.getProdCode());
            req.setBaseProdCode(entity.getBaseProdCode());
//            req.setQueryType(BompQueryTypeEnum.TEMP.getType());
            mchntProdResp = bMchntProdInfoService.getMchntProdInfoDtl(entity.getInstId(), bompMchntQueryService, genMerOrder(entity.getInstId()), req, BompQueryTypeEnum.TEMP);

            if (mchntProdResp == null || CollectionUtils.isEmpty(mchntProdResp.getMchntAuthCtrlInfoList()) && CollectionUtils.isEmpty(mchntProdResp.getMchntFeeInfoList()) && CollectionUtils.isEmpty(mchntProdResp.getMchntStageInfoList())) {
                mchntProdResp = new MchntProdInfoQueryResponse();
                ProdInfoQueryRequest prodInfoReq = new ProdInfoQueryRequest();
                prodInfoReq.setProdCode(entity.getProdCode());
                prodInfoReq.setBaseProdCode(entity.getBaseProdCode());
                prodInfoReq.setProdType(BompProdTypeEnum.STANDARD_PROD.getType());
                prodInfoReq.setUserId(user.getId());
                ProdInfoQueryResponse prodInfoResp = bMchntProdInfoService.getProdInfo(entity.getInstId(), bompPublicQueryService, genMerOrder(entity.getInstId()), prodInfoReq);
                bMchntProdInfoService.getMchntProdFromProd(prodInfoResp, mchntProdResp, entity.getBaseProdCode());
                flag = "add";
                disabled = "false";
            } else if (CollectionUtils.isNotEmpty(mchntProdResp.getMchntAuthCtrlInfoList()) || CollectionUtils.isNotEmpty(mchntProdResp.getMchntFeeInfoList()) || CollectionUtils.isNotEmpty(mchntProdResp.getMchntStageInfoList())) {
                Status = "Y";
                flag = "upd";
            }
            mchntProdResp.setMchntNo(entity.getMchntNo());
            mchntProdResp.setMchntSignType(mchntBase.getMchntBaseInfo().getMchntSignType());
            //新增时全产品统一分润
            if (IgasYesOrNoEnum.Yes.getType().equals(entity.getUnitedFeeFlag())) {
                List<MchntFeeInfoBean> mchntFeeInfoList = mchntProdResp.getMchntFeeInfoList();
                for (MchntFeeInfoBean mchntFee : mchntFeeInfoList) {
                    BeanUtils.copyProperties(entity, mchntFee);
                    mchntFee.setBaseProdCode(entity.getBaseProdCode());
                }
            }
            //07-微信支付 获取平台商户的微信进件信息
            if (BaseProdCodeEnum.WECHAT_PAY_PROD.getType().equals(entity.getBaseProdCode())) {
                if (Common.isNotBlank(mchntBase.getMchntBaseInfo().getPlatMchntNo())) {
                    PlatMchntWechatInfoQueryRequest reqPlat = new PlatMchntWechatInfoQueryRequest();
                    reqPlat.setPlatMchntNo(mchntBase.getMchntBaseInfo().getPlatMchntNo());
                    reqPlat.setUserId(user.getId());
                    PlatMchntWechatInfoQueryResponse respPlat = platMchntWechatInfoQuery(entity.getInstId(), reqPlat, bompMchntQueryService, genMerOrder(entity.getInstId()));
                    if (Common.isNotBlank(respPlat)) {
                        BeanUtils.copyProperties(respPlat, mchntProdResp);
                        mchntProdResp.setWechatSelfEntryFlag(IgasYesOrNoEnum.No.getType());
                    }
                } else {
                    mchntProdResp.setWechatSelfEntryFlag(IgasYesOrNoEnum.Yes.getType());
                    result.put("wechatSelfEntryFlag", "Y");
                }
            }
            //新增时默认设置不单独进件
//            mchntProdResp.setWechatSelfEntryFlag(IgasYesOrNoEnum.No.getType());
            result.put("unitedFeeFlag", entity.getUnitedFeeFlag());
        } else if (PageOptFlagEnum.OPT_FLAG_UPDATE.getType().equals(entity.getOptFlag())
                || PageOptFlagEnum.OPT_FLAG_USE.getType().equals(entity.getOptFlag())
                || PageOptFlagEnum.OPT_FLAG_STOP.getType().equals(entity.getOptFlag())
                || PageOptFlagEnum.OPT_FLAG_CANCEL.getType().equals(entity.getOptFlag())
                || PageOptFlagEnum.OPT_FLAG_VIEW.getType().equals(entity.getOptFlag())
                || PageOptFlagEnum.OPT_FLAG_CHECK.getType().equals(entity.getOptFlag())
                || PageOptFlagEnum.OPT_FLAG_CHECK_VIEW.getType().equals(entity.getOptFlag())) {

            MchntProdInfoQueryRequest req = new MchntProdInfoQueryRequest();
            req.setUserId(user.getId());
            req.setMchntNo(entity.getMchntNo());
            req.setProdCode(entity.getProdCode());
            req.setBaseProdCode(entity.getBaseProdCode());
            if ((BizDataAuditStatusEnum.AUDIT_STATUS_UPD_CHECKING.getType().equals(mchntBase.getAuditStatus())
                    || BizDataAuditStatusEnum.AUDIT_STATUS_STOP_CHECKING.getType().equals(mchntBase.getAuditStatus())
                    || BizDataAuditStatusEnum.AUDIT_STATUS_USE_CHECKING.getType().equals(mchntBase.getAuditStatus())
                    || BizDataAuditStatusEnum.AUDIT_STATUS_CANCEL_CHECKING.getType().equals(mchntBase.getAuditStatus()))
                    && !PageOptFlagEnum.OPT_FLAG_VIEW.getType().equals(entity.getOptFlag())
                    && !PageOptFlagEnum.OPT_FLAG_CHECK.getType().equals(entity.getOptFlag())
                    && !PageOptFlagEnum.OPT_FLAG_CHECK_VIEW.getType().equals(entity.getOptFlag())) {
                throw new RedpException("商户号[" + entity.getMchntNo() + "]的商户信息已被审批流程锁定！");
            }

            if (((PageOptFlagEnum.OPT_FLAG_UPDATE.getType().equals(entity.getOptFlag())) || PageOptFlagEnum.OPT_FLAG_CHECK.getType().equals(entity.getOptFlag()) || PageOptFlagEnum.OPT_FLAG_CHECK_VIEW.getType().equals(entity.getOptFlag()))
                    && (BizDataAuditStatusEnum.AUDIT_STATUS_UPD_REJECT.getType().equals(mchntBase.getAuditStatus()) || BizDataAuditStatusEnum.AUDIT_STATUS_ADD_REJECT.getType().equals(mchntBase.getAuditStatus())
                    || BizDataAuditStatusEnum.AUDIT_STATUS_UPD_NOTCOMMIT.getType().equals(mchntBase.getAuditStatus()) || BizDataAuditStatusEnum.AUDIT_STATUS_ADD_NOTCOMMIT.getType().equals(mchntBase.getAuditStatus())
                    || BizDataStatusEnum.STATUS_DRAFT.getType().equals(mchntBase.getMchntStatus()) || BizDataAuditStatusEnum.AUDIT_STATUS_UPD_CHECKING.getType().equals(mchntBase.getAuditStatus()))) {
                //新增、修改拒绝时查询临时表数据
                mchntProdResp = bMchntProdInfoService.getMchntProdInfoDtl(entity.getInstId(), bompMchntQueryService, genMerOrder(entity.getInstId()), req, BompQueryTypeEnum.TEMP);
            } else {
                //查询正式表数据
                mchntProdResp = bMchntProdInfoService.getMchntProdInfoDtl(entity.getInstId(), bompMchntQueryService, genMerOrder(entity.getInstId()), req, BompQueryTypeEnum.REAL);
            }


            if (mchntProdResp == null || CollectionUtils.isEmpty(mchntProdResp.getMchntAuthCtrlInfoList()) && CollectionUtils.isEmpty(mchntProdResp.getMchntFeeInfoList()) && CollectionUtils.isEmpty(mchntProdResp.getMchntStageInfoList())) {
                disabled = "false";
                if (PageOptFlagEnum.OPT_FLAG_UPDATE.getType().equals(entity.getOptFlag())
                        || PageOptFlagEnum.OPT_FLAG_VIEW.getType().equals(entity.getOptFlag())) {
                    mchntProdResp = new MchntProdInfoQueryResponse();
                    //修改时如果商户产品信息查询返回为空则将标准产品数据查出来并组织成 MchntBaseInfoQueryResponse对象
                    ProdInfoQueryRequest prodInfoReq = new ProdInfoQueryRequest();
                    prodInfoReq.setUserId(user.getId());
                    prodInfoReq.setBaseProdCode(entity.getBaseProdCode());
                    if (entity.getProdCode().equals("DF")) {
                        prodInfoReq.setProdCode(entity.getProdCode());
                        prodInfoReq.setProdType(BompProdTypeEnum.STANDARD_PROD.getType());
                    } else {
                        prodInfoReq.setProdType(BompProdTypeEnum.BASIC_PROD.getType());
                    }
                    ProdInfoQueryResponse prodInfoResp = bMchntProdInfoService.getProdInfo(entity.getInstId(), bompPublicQueryService, genMerOrder(entity.getInstId()), prodInfoReq);
                    bMchntProdInfoService.getMchntProdFromProd(prodInfoResp, mchntProdResp, entity.getBaseProdCode());
                    mchntProdResp.setMchntNo(entity.getMchntNo());
                    if (PageOptFlagEnum.OPT_FLAG_UPDATE.getType().equals(entity.getOptFlag())) {
                        flag = "add";
                    }
                    /*** 测试数据 结束 ****/
                } else {
                    //修改、新增、查看以外的其他操作查询不到商户产品信息时则报错
                    log.error("法人行[" + entity.getInstId() + "]商户号[" + entity.getMchntNo() + "]没有查询到对应的商户产品信息信息");
                    throw new RedpException("法人行[" + entity.getInstId() + "]商户号[" + entity.getMchntNo() + "]没有查询到对应的商户产品信息信息");
                }
            }


            //07-微信支付 获取平台商户的微信进件信息
            if (BaseProdCodeEnum.WECHAT_PAY_PROD.getType().equals(entity.getBaseProdCode())) {

                if (Common.isNotBlank(mchntBase.getMchntBaseInfo().getPlatMchntNo())) {
                    PlatMchntWechatInfoQueryRequest reqPlat = new PlatMchntWechatInfoQueryRequest();
                    reqPlat.setPlatMchntNo(mchntBase.getMchntBaseInfo().getPlatMchntNo());
                    reqPlat.setUserId(user.getId());
                    PlatMchntWechatInfoQueryResponse respPlat = platMchntWechatInfoQuery(entity.getInstId(), reqPlat, bompMchntQueryService, genMerOrder(entity.getInstId()));
                    if (Common.isNotBlank(respPlat)) {
                        if ((Common.isNotBlank(mchntProdResp.getWechatAppid()) && !respPlat.getWechatAppid().equals(mchntProdResp.getWechatAppid()))
                                || (Common.isNotBlank(mchntProdResp.getWechatMiniAppid()) && !respPlat.getWechatMiniAppid().equals(mchntProdResp.getWechatMiniAppid()))) {
                        } else {
                            BeanUtils.copyProperties(respPlat, mchntProdResp);
                        }
                    }
                } else {
                    mchntProdResp.setWechatSelfEntryFlag(IgasYesOrNoEnum.Yes.getType());
                    result.put("wechatSelfEntryFlag", "Y");
                }


                //05-银行卡支付 获取银联全渠道商户号
            } else if (BaseProdCodeEnum.BANK_CARD_PAY_PROD.getType().equals(entity.getBaseProdCode()) || BaseProdCodeEnum.UPQR_PROD.getType().equals(entity.getBaseProdCode())) {
                List<LabelValueBean> list = Lists.newArrayList();
                if (Common.isNotBlank(mchntProdResp.getCupsChannelMchntNo())) {
                    String cupsMchntNos = mchntProdResp.getCupsChannelMchntNo();
                    result.put("cupsMchntNoList", cupsMchntNos);
                }
            }
            result.put("unitedFeeFlag", Common.isBlank(entity.getUnitedFeeFlag()) ? IgasYesOrNoEnum.No.getType() : entity.getUnitedFeeFlag());
            //TODO 审核对比功能屏蔽
            /*if ((PageOptFlagEnum.OPT_FLAG_CHECK.getType().equals(entity.getOptFlag()) || PageOptFlagEnum.OPT_FLAG_CHECK_VIEW.getType().equals(entity.getOptFlag())) && (BizDataAuditStatusEnum.AUDIT_STATUS_UPD_REJECT.getType().equals(mchntBase.getAuditStatus())
                    || BizDataAuditStatusEnum.AUDIT_STATUS_UPD_NOTCOMMIT.getType().equals(mchntBase.getAuditStatus()) || BizDataAuditStatusEnum.AUDIT_STATUS_UPD_CHECKING.getType().equals(mchntBase.getAuditStatus()))) {

                MchntProdInfoQueryRequest reqReal = new MchntProdInfoQueryRequest();
                reqReal.setUserId(user.getId());
                reqReal.setMchntNo(entity.getMchntNo());
                reqReal.setProdCode(entity.getProdCode());
                reqReal.setBaseProdCode(entity.getBaseProdCode());
                MchntProdInfoQueryResponse mchntProdRespReal = bMchntProdInfoService.getMchntProdInfoDtl(entity.getInstId(), bompMchntQueryService, genMerOrder(entity.getInstId()), reqReal, BompQueryTypeEnum.REAL);
                if (Common.isNotBlank(mchntProdRespReal)) {

                    //对比费率
                    List<MchntFeeInfoBean> feeInfoTmps = mchntProdResp.getMchntFeeInfoList();
                    List<MchntFeeInfoBean> feeInfoFormals = mchntProdRespReal.getMchntFeeInfoList();
                    //产品费率的类型是固定的，不允许新增、删除，只能修改
                    Map<String, List<LabelValueBean>> feeUpdCompare = Maps.newHashMap();
                    for (MchntFeeInfoBean fee : feeInfoTmps) {
                        for (MchntFeeInfoBean feeFormal : feeInfoFormals) {
                            if (fee.getId().equals(feeFormal.getId())) {
                                List<LabelValueBean> compare = CommonUtils.compareData(fee, feeFormal, MchntFeeInfoBean.class);
                                if (CollectionUtils.isNotEmpty(compare)) {
                                    feeUpdCompare.put(feeFormal.getId(), compare);
                                }
                            }
                        }
                    }
                    if (Common.isNotBlank(feeUpdCompare)) {
                        result.put("compareFee", JSON.toJSONString(feeUpdCompare));
                    }

                    //分期
                    List<MchntStageInfoBean> stageInfoTmps = mchntProdResp.getMchntStageInfoList();
                    List<MchntStageInfoBean> stageInfoFormals = mchntProdRespReal.getMchntStageInfoList();
                    CompareDataBean compareStage = bMchntProdInfoService.getStageCompareFileById(stageInfoTmps, stageInfoFormals);
                    if (Common.isNotBlank(compareStage)) {
                        result.put("compareStageUpd", JSON.toJSONString(compareStage.getUpdCompare()));
                        result.put("compareStageAdd", JSON.toJSONString(compareStage.getAddCompare()));
                        result.put("compareStageDel", JSON.toJSONString(compareStage.getDelCompare()));
                    }

                    List<MchntAuthCtrlInfoBean> txnGroupListTmps = mchntProdResp.getMchntAuthCtrlInfoList().stream().collect(Collectors.collectingAndThen(
                            Collectors.toCollection(() -> new TreeSet<>(Comparator.comparing(o -> o.getBaseProdCode() + ":" + o.getTxnGroup()))), ArrayList::new));

                    List<MchntAuthCtrlInfoBean> selectedTxnNumTmps = mchntProdResp.getMchntAuthCtrlInfoList();

                    List<PTxnGroup> txnGroupTmps = bMchntProdInfoService.getTxnGroup(txnGroupListTmps, selectedTxnNumTmps, map, entity.getInstId(), entity.getProdCode());

                    List<MchntAuthCtrlInfoBean> txnGroupListFormals = mchntProdRespReal.getMchntAuthCtrlInfoList().stream().collect(Collectors.collectingAndThen(
                            Collectors.toCollection(() -> new TreeSet<>(Comparator.comparing(o -> o.getBaseProdCode() + ":" + o.getTxnGroup()))), ArrayList::new));

                    List<MchntAuthCtrlInfoBean> selectedTxnNumFormals = mchntProdRespReal.getMchntAuthCtrlInfoList();

                    List<PTxnGroup> txnGroupFormals = bMchntProdInfoService.getTxnGroup(txnGroupListFormals, selectedTxnNumFormals, map, entity.getInstId(), entity.getProdCode());

                    CompareDataBean compareTxn = bMchntProdInfoService.getAuthCompareFileById(selectedTxnNumTmps, selectedTxnNumFormals);

                    if (Common.isNotBlank(compareTxn)) {
                        result.put("compareTxnUpd", JSON.toJSONString(compareTxn.getUpdCompare()));
                        result.put("compareTxnAdd", JSON.toJSONString(compareTxn.getAddCompare()));
                        result.put("compareTxnDel", JSON.toJSONString(compareTxn.getDelCompare()));
                    }

                    CompareDataBean compareTxnGroup = bMchntProdInfoService.getTxnGroupCompareFileById(txnGroupTmps, txnGroupFormals);
                    if (Common.isNotBlank(compareTxnGroup)) {
                        result.put("compareTxnGroupUpd", JSON.toJSONString(compareTxnGroup.getUpdCompare()));
                        result.put("compareTxnGroupAdd", JSON.toJSONString(compareTxnGroup.getAddCompare()));
                        result.put("compareTxnGroupDel", JSON.toJSONString(compareTxnGroup.getDelCompare()));
                    }

                    List<LabelValueBean> compareBeans = CommonUtils.compareData(mchntProdResp, mchntProdRespReal, MchntProdInfoQueryResponse.class);
                    if (CollectionUtils.isNotEmpty(compareBeans)) {
                        result.put("compareBeans", JSON.toJSONString(compareBeans));
                    }

                }
            }*/
        } else {
            log.error("不支持的操作");
            throw new RedpException("不支持的操作");
        }


        //查询基础产品选中交易
        ProdInfoQueryRequest prodInfoReq = new ProdInfoQueryRequest();
        prodInfoReq.setUserId(user.getId());
        prodInfoReq.setBaseProdCode(entity.getBaseProdCode());
        prodInfoReq.setProdType(BompProdTypeEnum.BASIC_PROD.getType());
        ProdInfoQueryResponse prodInfoResp = bMchntProdInfoService.getProdInfo(entity.getInstId(), bompPublicQueryService, genMerOrder(entity.getInstId()), prodInfoReq);
        List<ProdAuthCtrlBean> prodAuthCtrlList = prodInfoResp.getProdAuthCtrlList();
        //根据BaseProdCode、TxnGroup 去重
        List<ProdAuthCtrlBean> txnGroupList = null;
        if (CollectionUtils.isNotEmpty(prodAuthCtrlList)) {
            txnGroupList = prodAuthCtrlList.stream().collect(Collectors.collectingAndThen(
                    Collectors.toCollection(() -> new TreeSet<>(Comparator.comparing(o -> o.getTxnGroup()))), ArrayList::new));
        }

        List<MchntAuthCtrlInfoBean> mchntAuthCtrlList = mchntProdResp.getMchntAuthCtrlInfoList();
        List<PTxnGroup> txnGroups = bMchntProdInfoService.getBProdAuthCtrlTxnGroup(prodAuthCtrlList, txnGroupList, map, entity.getInstId(), entity.getProdCode());

        //对比商户选择的交易权限 选中的IsChecked yes
        if (CollectionUtils.isNotEmpty(txnGroups)) {
            //循环交易大类
            for (PTxnGroup pTxnGroup : txnGroups) {
                pTxnGroup.setTxnGroupName(map.get(pTxnGroup.getTxnGroup()));
                List<PTxnAuthMap> pTxnAuthMaps = pTxnGroup.getpTxnAuthMaps();
                //判断商户已选交易权限是否为空
                if (CollectionUtils.isNotEmpty(mchntAuthCtrlList)) {
                    //循环商户交易权限
                    for (MchntAuthCtrlInfoBean mchntauthctrlinfobean : mchntAuthCtrlList) {
                        if (pTxnGroup.getTxnGroup().equals(mchntauthctrlinfobean.getTxnGroup())) {//如果当前记录的交易大类查出有值  则 对需要展示的交易大类 复选框勾上
                            pTxnGroup.setIsChecked(BusinessContainer.YES);
                        }
                        for (PTxnAuthMap pTxnAuthMap : pTxnAuthMaps) {
                            if (pTxnAuthMap.getTxnNum().equals(mchntauthctrlinfobean.getTxnNum()) && pTxnAuthMap.getBizType().equals(mchntauthctrlinfobean.getBizType())) {//如果此处的交易查出有值 则 对需要展示的交易 复选框勾上
                                pTxnAuthMap.setIsChecked(BusinessContainer.YES);
                                pTxnAuthMap.setId(mchntauthctrlinfobean.getId());
                                pTxnAuthMap.setSupportAcctType(mchntauthctrlinfobean.getSupportAcctType());
                                if (!BusinessContainer.YES.equals(pTxnGroup.getIsChecked())) {//如果交易被选中时，将交易大类选中
                                    pTxnGroup.setIsChecked(BusinessContainer.YES);
                                }
                            }
                        }
                    }
                }
            }
        }

        SimpleDateFormat fmtdt1 = new SimpleDateFormat("yyyyMMdd");
        DateFormat df = new SimpleDateFormat("yyyyMMdd");
        String date = fmtdt1.format(new Date());
        Date parse = null;
        try {
            parse = df.parse(date);
            String[] codes = {"05", "04", "01", "02", "03", "13", "11", "12", "06", "07", "99"};
            if (CollectionUtils.isNotEmpty(mchntProdResp.getMchntFeeInfoList())) {
                List<MchntFeeInfoBean> mchntFeeInfoList = new ArrayList<>();
                for (int i = 0; i < codes.length; i++) {
                    for (MchntFeeInfoBean mchntfeeinfobean : mchntProdResp.getMchntFeeInfoList()) {
                        Date parse1 = df.parse(mchntfeeinfobean.getFeeExpiryDate());
                        if (parse1.getTime() > parse.getTime() && mchntfeeinfobean.getFeeType().equals(codes[i])) {
                            mchntFeeInfoList.add(mchntfeeinfobean);
                        }
                    }
                }
                mchntProdResp.setMchntFeeInfoList(mchntFeeInfoList);
            }
            if (CollectionUtils.isNotEmpty(mchntProdResp.getMchntStageInfoList())) {
                List<MchntStageInfoBean> mchntStageInfoList = new ArrayList<>();
                for (MchntStageInfoBean mchntstageinfobean : mchntProdResp.getMchntStageInfoList()) {
                    Date parse1 = df.parse(mchntstageinfobean.getFeeExpiryDate());
                    if (parse1.getTime() > parse.getTime()) {
                        mchntStageInfoList.add(mchntstageinfobean);
                    }
                }
                mchntProdResp.setMchntStageInfoList(mchntStageInfoList);
            }
            //第一次查询分期产品 RecordStatus01==Y
            if (CollectionUtils.isNotEmpty(mchntProdResp.getMchntStageInfoList())) {
                List<MchntStageInfoBean> mchntStageInfoList = new ArrayList<>();
                for (MchntStageInfoBean mchntstageinfobean : mchntProdResp.getMchntStageInfoList()) {
                    Date parse1 = null;
                    parse1 = df.parse(mchntstageinfobean.getFeeExpiryDate());
                    if (parse1.getTime() > parse.getTime()) {
                        if (mchntstageinfobean.getRecordStatus().equals("01")) {
                            mchntstageinfobean.setRecordStatus("Y");
                            mchntStageInfoList.add(mchntstageinfobean);
                        } else {
                            mchntStageInfoList.add(mchntstageinfobean);
                        }
                    }
                    mchntProdResp.setMchntStageInfoList(mchntStageInfoList);
                }
            }
        } catch (ParseException e) {
            throw new RedpException("日期转换错误");
        }
        //界面用 feeype 作为 key 从map中取中文描述
        Map<Object, String> feeTypeMap = EnumUtils.EnumToMap(FeeTypeEnum.class);
        String unitedFeeFlag = Common.isBlank(entity.getUnitedFeeFlag()) ? "" : entity.getUnitedFeeFlag().toString();
        result.put("feeTypeMap", feeTypeMap);
        result.put("entity", mchntProdResp);
        result.put("pTxnGroups", txnGroups);
        result.put("optFlag", optFlag);
        result.put("flag", flag);
        result.put("Status", Status);
        result.put("instId", entity.getInstId());
        result.put("mchntNo", entity.getMchntNo());
        result.put("prodCode", entity.getProdCode());
        result.put("baseProdCode", entity.getBaseProdCode());
        result.put("baseProdName", entity.getBaseProdName());
        result.put("unitedFeeFlag", unitedFeeFlag);
        result.put("disabled", disabled);
        return result;
    }

    @Override
    public OperationResult mchntProdDtlSave(MchntProdManagerVO entity) throws RedpException {
        if (CollectionUtils.isNotEmpty(entity.getMchntBaseProdList())) {
            String cupsChannelMchntNo = entity.getMchntBaseProdList().get(0).getCupsChannelMchntNo();
            if (Common.isNotBlank(cupsChannelMchntNo)) {
                String mchntno = cupsChannelMchntNo.replaceAll("&amp;quot;", "\"");
                entity.getMchntBaseProdList().get(0).setCupsChannelMchntNo(mchntno);
            }
        }
        UpmpUserInfoVO user = CommonUtils.getCurrentUser(upmpSysParamService);
        String instId = entity.getInstId();
        CommonUtils.validateUserInst(entity.getInstId(), user);
        //新增操作先查一次看之前是否已经保存，如果已经保存则修改
        if (PageOptFlagEnum.OPT_FLAG_ADD.getType().equals(entity.getOptFlag())) {
            MchntProdInfoQueryRequest reqQry = new MchntProdInfoQueryRequest();
            reqQry.setMchntNo(entity.getMchntNo());
            reqQry.setUserId(user.getId());
            reqQry.setProdCode(entity.getProdCode());
            if (CollectionUtils.isNotEmpty(entity.getMchntBaseProdList())) {
                MchntBaseProdManagerVO vo = entity.getMchntBaseProdList().get(0);
                reqQry.setBaseProdCode(vo.getBaseProdCode());
                MchntProdInfoQueryResponse resp = bMchntProdInfoService.getMchntProdInfoDtl(entity.getInstId(), bompMchntQueryService, genMerOrder(entity.getInstId()), reqQry, BompQueryTypeEnum.REAL);
                if (Common.isNotBlank(resp)) {//如果应答非空则认为是修改
                    entity.setOptFlag(PageOptFlagEnum.OPT_FLAG_UPDATE.getType());
                }
            }
        }

        MchntProdInfoManageRequest req = new MchntProdInfoManageRequest();
        bMchntProdInfoService.getMchntProdManageFromVO(req, entity);
        req.setUserId(user.getId());

        String manageOprType = "";
        if (PageOptFlagEnum.OPT_FLAG_ADD.getType().equals(entity.getOptFlag())) {
            manageOprType = BompManageOprTypeEnum.CREATE.getType();
        } else if (PageOptFlagEnum.OPT_FLAG_UPDATE.getType().equals(entity.getOptFlag())) {
            manageOprType = BompManageOprTypeEnum.MODIFY.getType();
        } else {
            throw new RedpException("不支持的操作");
        }
        return bMchntProdInfoService.mchntProdSave(instId, req, bompMchntManageService, upmpPrivilegeCheckService, genMerOrder(entity.getInstId()), entity.getOptFlag(), manageOprType);
    }

    @Override
    public OperationResult acctAuth(SettleAcctInfoVO entity) throws RedpException {
        UpmpUserInfoVO user = CommonUtils.getCurrentUser(upmpSysParamService);
        CommonUtils.validateUserInst(entity.getInstId(), user);
        String traceNo = genMerOrder(entity.getInstId());
        AcctRealNameAuthRequest req = new AcctRealNameAuthRequest();
        req.setHeader(CommonUtils.packageBompHeader(traceNo, BompTxnNumEnum.acctRealNameAuth.getType(), entity.getInstId(), null));
        req.setAcctNo(entity.getSettleAcctNo());
        req.setAcctName(entity.getSettleAcctName());
        req.setSettleAcctType(entity.getSettleAcctType());
        req.setUserId(user.getId());


        log.info("商户编号为：" + entity.getMchntNo() + "的商户，" + BompTxnNumEnum.acctRealNameAuth.getDesc() + "请求报文：" + JSON.toJSONString(req));

        Map<String, Object> result = Maps.newHashMap();
        try {
            Result<AcctRealNameAuthResponse> response = bompMchntManageService.acctRealNameAuth(req);


            log.info("商户编号为：" + entity.getMchntNo() + "的商户，" + BompTxnNumEnum.acctRealNameAuth.getDesc() + "交易返回报文：" + JSON.toJSONString(response));

            if (response.isSuccess()) {
                AcctRealNameAuthResponse resp = response.getResult();
                // 返回码：00000000-进件成功，其他均视为失败
                if (BusinessContainer.BSPS_SUCCESS.equals(resp.getRespCode())) {
                    if (IgasYesOrNoEnum.Yes.getType().equals(resp.getAuthResult())) {
                        result.put("settleAcctBankNo", resp.getOpenBankNo());
                        result.put("settleAcctBankName", resp.getOpenBankName());
                        result.put("respCode", resp.getRespCode());
                        result.put("respMsg", resp.getRespDesc());
                        log.info("商户编号为：" + entity.getMchntNo() + "的商户，" + BompTxnNumEnum.acctRealNameAuth.getDesc() + "账户状态正常");
                        return OperationResult.buildSuccessResult(BompTxnNumEnum.acctRealNameAuth.getDesc() + "交易成功", result);
                    } else {
                        result.put("respCode", BusinessContainer.ERROR);
                        result.put("respMsg", "账户状态异常");
                        log.error("商户编号为：" + entity.getMchntNo() + "的商户，" + BompTxnNumEnum.acctRealNameAuth.getDesc() + "账户状态异常");
                        return OperationResult.buildFailureResult(BompTxnNumEnum.acctRealNameAuth.getDesc() + "失败", result);
                    }
                } else {
                    result.put("respCode", resp.getRespCode());
                    result.put("respMsg", resp.getRespDesc());
                    return OperationResult.buildFailureResult(BompTxnNumEnum.acctRealNameAuth.getDesc() + "失败", result);
                }
            } else {
                result.put("resCode", BusinessContainer.ERROR);
                result.put("resMsg", BompTxnNumEnum.acctRealNameAuth.getDesc() + "没有获得返回报文");
                log.error("商户编号为：" + entity.getMchntNo() + "的商户，" + BompTxnNumEnum.acctRealNameAuth.getDesc() + "交易没有获得返回信息");
                return OperationResult.buildFailureResult(BompTxnNumEnum.acctRealNameAuth.getDesc() + "失败", result);
            }
        } catch (Exception e) {
            // TODO: handle exception
            result.put("resCode", BusinessContainer.ERROR);
            result.put("resMsg", e.getMessage());
            log.error("商户编号为：" + entity.getMchntNo() + "的商户，" + BompTxnNumEnum.acctRealNameAuth.getDesc() + "交易出现异常，异常信息：" + e.getMessage(), e);
            return OperationResult.buildFailureResult(BompTxnNumEnum.acctRealNameAuth.getDesc() + "失败", result);
        }
    }

    public OperationResult mchntStatusManage(String instId, MchntStatusManageRequest req, BompMchntManageService bompMchntManageService,
                                             String traceNo, String optFlag) throws RedpException {
        UpmpUserInfoVO user = CommonUtils.getCurrentUser(upmpSysParamService);
        /**商户写死必须审核*/
        req.setHeader(CommonUtils.packageBompHeader(traceNo, BompTxnNumEnum.mchntStatusManage.getType(), instId, null));
        UpmpPrivilegeCheck privilegeCheck = upmpPrivilegeCheckService.getPrivilegeCheckByPrivilegeCode(instId,
                oprBtnNamePrefix + BusinessContainer.AUTH_PRIVILEGE_CODE_SPLIT + EnumUtils.getEnumDescriotionByValue(optFlag, PageOptFlagEnum.class, "getType", "getDesc").toString());
        if (null != privilegeCheck && BusinessContainer.YES.equals(privilegeCheck.getChecked())) {
            req.setChecked(BompAuditFlagEnum.CHECK.getType());
            req.setOprMenuId(oprMenuId);
            req.setOprMenuName(oprMenuName);
            req.setWebNextUrl(webNextUrl);
        } else {
            /*req.setChecked(BompAuditFlagEnum.NO_CHECK.getType());*/
            req.setChecked(BompAuditFlagEnum.CHECK.getType());
            req.setOprMenuId(oprMenuId);
            req.setOprMenuName(oprMenuName);
            req.setWebNextUrl(webNextUrl);
        }


        Map<String, Object> result = Maps.newHashMap();
        try {

            log.info("法人行[" + instId + "],用户标识[" + req.getUserId() + "],商户号[" + req.getMchntNo() + "]" + BompTxnNumEnum.mchntStatusManage.getDesc() + "交易请求报文：" + JSON.toJSONString(req));

            Result<MchntStatusManageResponse> response = bompMchntManageService.mchntStatusManage(req);

            log.info("法人行[" + instId + "],用户标识[" + req.getUserId() + "],商户号[" + req.getMchntNo() + "]" + BompTxnNumEnum.mchntStatusManage.getDesc() + "交易返回报文：" + JSON.toJSONString(response));
            if (response.isSuccess()) {
                MchntStatusManageResponse resp = response.getResult();
                // 返回码：00000000-进件成功，其他均视为失败
                if (BusinessContainer.BSPS_SUCCESS.equals(resp.getRespCode())) {
                    result.put("respCode", resp.getRespCode());
                    result.put("respMsg", resp.getRespDesc());
                    log.info("法人行[" + instId + "],用户标识[" + req.getUserId() + "],商户号[" + req.getMchntNo() + "]" + BompTxnNumEnum.mchntStatusManage.getDesc() + "交易成功");
                    return OperationResult.buildSuccessResult(BompTxnNumEnum.mchntStatusManage.getDesc() + "交易成功", result);
                } else {
                    result.put("respCode", resp.getRespCode());
                    result.put("respMsg", resp.getRespDesc());
                    return OperationResult.buildFailureResult(BompTxnNumEnum.mchntStatusManage.getDesc() + "交易失败", result);
                }
            } else {
                result.put("resCode", BusinessContainer.ERROR);
                result.put("resMsg", BompTxnNumEnum.mchntStatusManage.getDesc() + "没有获得返回报文");
                log.error("法人行[" + instId + "],用户标识[" + req.getUserId() + "],商户号[" + req.getMchntNo() + "]" + BompTxnNumEnum.mchntStatusManage.getDesc() + "交易没有获得返回信息");
                return OperationResult.buildFailureResult(BompTxnNumEnum.mchntStatusManage.getDesc() + "交易失败", result);
            }
        } catch (Exception e) {
            // TODO: handle exception
            result.put("resCode", BusinessContainer.ERROR);
            result.put("resMsg", e.getMessage());
            log.error("法人行[" + instId + "],用户标识[" + req.getUserId() + "],商户号[" + req.getMchntNo() + "]" + BompTxnNumEnum.mchntStatusManage.getDesc() + "交易出现异常，异常信息：" + e.getMessage(), e);
//            throw new RedpException("商户编号为：[" + req.getMchntNo() + "]的商户，"+BompTxnNumEnum.mchntProdInfoManage.getDesc()+"交易出现异常，异常信息："+e.getMessage());
            return OperationResult.buildFailureResult(BompTxnNumEnum.mchntStatusManage.getDesc() + "交易失败", result);
        }
    }

    /**
     * 商户终端及二维码数量查询
     *
     * @param instId
     * @param req
     * @param bompQueryService
     * @param traceNo
     * @return
     * @throws RedpException
     */
    public TermAndQrcodeNumQueryResponse termAndQrcodeNumQuery(String instId, TermAndQrcodeNumQueryRequest req, BompMchntQueryService bompQueryService, String traceNo) throws RedpException {

        req.setHeader(CommonUtils.packageBompHeader(traceNo, BompTxnNumEnum.termAndQrcodeNumQuery.getType(), instId, null));
        try {
            log.info("法人行[" + instId + "],用户标识[" + req.getUserId() + "]" + BompTxnNumEnum.termAndQrcodeNumQuery.getDesc() + "交易请求报文：" + JSON.toJSONString(req));

            Result<TermAndQrcodeNumQueryResponse> response = bompQueryService.termAndQrcodeNumQuery(req);
            log.info("法人行[" + instId + "],用户标识[" + req.getUserId() + "]" + BompTxnNumEnum.termAndQrcodeNumQuery.getDesc() + "交易返回报文：" + JSON.toJSONString(response));
            if (response.isSuccess()) {
                TermAndQrcodeNumQueryResponse resp = response.getResult();
                // 返回码：00000000-进件成功，其他均视为失败
                if (BusinessContainer.BSPS_SUCCESS.equals(resp.getRespCode())) {
                    log.info("法人行[" + instId + "],用户标识[" + req.getUserId() + "]" + BompTxnNumEnum.termAndQrcodeNumQuery.getDesc() + "交易成功");
                    return resp;
                } else {
                    log.error("法人行[" + instId + "],用户标识[" + req.getUserId() + "]" + BompTxnNumEnum.termAndQrcodeNumQuery.getDesc() + "交易失败");
                    return null;
                }
            } else {
                log.error("法人行[" + instId + "],用户标识[" + req.getUserId() + "]" + BompTxnNumEnum.termAndQrcodeNumQuery.getDesc() + "交易没有获得返回信息");
                return null;
            }
        } catch (Exception e) {
            // TODO: handle exception
            log.error("法人行[" + instId + "],用户标识[" + req.getUserId() + "]" + BompTxnNumEnum.termAndQrcodeNumQuery.getDesc() + "交易出现异常，异常信息：" + e.getMessage(), e);
            throw new RedpException("法人行[" + instId + "],用户标识[" + req.getUserId() + "]" + BompTxnNumEnum.termAndQrcodeNumQuery.getDesc() + "交易出现异常，异常信息：" + e.getMessage());
        }
    }

    /**
     * 平台商户微信进件信息查询
     *
     * @param instId
     * @param req
     * @param bompQueryService
     * @param traceNo
     * @return
     * @throws RedpException
     */
    public PlatMchntWechatInfoQueryResponse platMchntWechatInfoQuery(String instId, PlatMchntWechatInfoQueryRequest req, BompMchntQueryService bompQueryService, String traceNo) throws RedpException {

        req.setHeader(CommonUtils.packageBompHeader(traceNo, BompTxnNumEnum.platMchntWechatInfoQuery.getType(), instId, null));
        try {
            log.info("法人行[" + instId + "],用户标识[" + req.getUserId() + "]" + BompTxnNumEnum.platMchntWechatInfoQuery.getDesc() + "交易请求报文：" + JSON.toJSONString(req));

            Result<PlatMchntWechatInfoQueryResponse> response = bompQueryService.platMchntWechatInfoQuery(req);
            log.info("法人行[" + instId + "],用户标识[" + req.getUserId() + "]" + BompTxnNumEnum.platMchntWechatInfoQuery.getDesc() + "交易返回报文：" + JSON.toJSONString(response));
            if (response.isSuccess()) {
                PlatMchntWechatInfoQueryResponse resp = response.getResult();
                // 返回码：00000000-进件成功，其他均视为失败
                if (BusinessContainer.BSPS_SUCCESS.equals(resp.getRespCode())) {
                    log.info("法人行[" + instId + "],用户标识[" + req.getUserId() + "]" + BompTxnNumEnum.platMchntWechatInfoQuery.getDesc() + "交易成功");
                    return resp;
                } else {
                    log.error("法人行[" + instId + "],用户标识[" + req.getUserId() + "]" + BompTxnNumEnum.platMchntWechatInfoQuery.getDesc() + "交易失败");
                    return null;
                }
            } else {
                log.error("法人行[" + instId + "],用户标识[" + req.getUserId() + "]" + BompTxnNumEnum.platMchntWechatInfoQuery.getDesc() + "交易没有获得返回信息");
                return null;
            }
        } catch (Exception e) {
            // TODO: handle exception
            log.error("法人行[" + instId + "],用户标识[" + req.getUserId() + "]" + BompTxnNumEnum.platMchntWechatInfoQuery.getDesc() + "交易出现异常，异常信息：" + e.getMessage(), e);
            throw new RedpException("法人行[" + instId + "],用户标识[" + req.getUserId() + "]" + BompTxnNumEnum.platMchntWechatInfoQuery.getDesc() + "交易出现异常，异常信息：" + e.getMessage());
        }
    }

    @Override
    public Map<String, Object> openCashOut(UpmpBMchntBaseInfo entity) throws RedpException {
        Map<String, Object> result = Maps.newHashMap();
        UpmpUserInfoVO user = CommonUtils.getCurrentUser(upmpSysParamService);
        CommonUtils.validateUserInst(entity.getInstId(), user);
        MchntSettleAcctInfoQueryRequest req = new MchntSettleAcctInfoQueryRequest();
        req.setUserId(user.getId());
        req.setMchntNo(entity.getMchntNo());
        MchntSettleAcctInfoQueryResponse resp = bMchntAcctInfoService.mchntSettleInfoQuery(entity.getInstId(), req, bompMchntQueryService, genMerOrder(entity.getInstId()), BompQueryTypeEnum.REAL);

        UpmpBMchntFeeInfo feeInfo = new UpmpBMchntFeeInfo();
        /** 设置初始值以通过必输项校验 **/
        feeInfo.setInstId(entity.getInstId());
        feeInfo.setMchntNo(entity.getMchntNo());
        feeInfo.setAuditStatus(BizDataAuditStatusEnum.AUDIT_STATUS_ADD_PASS.getType());
        feeInfo.setCreateTime(DateUtils.formatDate(new Date(), DateUtils.DEFAULT_TIME_FORMAT + ".SSS"));
        feeInfo.setOprId(user.getId());
        feeInfo.setOptFlag(PageOptFlagEnum.OPT_FLAG_UPDATE.getType());
        feeInfo.setBaseProdCode(BaseProdCodeEnum.COMMOM_PROD.getType());

        //查询系统参数 是否展示提现手续费
        ParamQueryRequest req1 = new ParamQueryRequest();
        req1.setUserId(user.getId());
        req1.setParamKey(ParamQueryKeyEnum.CASH_WITHDRAWAL.getType());
        req1.setParamType(BusinessContainer.MCMP_TO_BOMP_PARAM_TYPE);
        ParamQueryResponse paramQueryResponse = paramQuery(entity.getInstId(), req1, genMerOrder(entity.getInstId()));
        if (Common.isNotBlank(paramQueryResponse)) {
            List<SysParamBean> sysParamList = paramQueryResponse.getSysParamList();
            if (CollectionUtils.isEmpty(sysParamList)) {
                if (Common.isNotBlank(resp)) {
                    BeanUtils.copyProperties(resp.getCashWithdrawalFeeInfoBean(), feeInfo);
                }
            }
        }
        result.put("entity", feeInfo);
        result.put("feeTypeName", FeeTypeEnum.CASHOUT.getDesc());
        return result;
    }

    @Override
    public OperationResult getreqD0(String instId, String mchntNo) throws RedpException {
        UpmpUserInfoVO user = CommonUtils.getCurrentUser(upmpSysParamService);
        CommonUtils.validateUserInst(instId, user);
        //1、根据商户号调用商户是否能开通D0及提现查询接口，返回是则继续，否则提示商户不能开通D0及提现并退出
        MchntD0QueryRequest reqD0 = new MchntD0QueryRequest();
        reqD0.setUserId(user.getId());
        reqD0.setMchntNo(mchntNo);
        MchntD0QueryResponse d0Resp = mchntD0Query(instId, reqD0, bompMchntPublicDealService, genMerOrder(instId));
        if (Common.isBlank(d0Resp) || d0Resp.getCashDrawFlag().equals(IgasYesOrNoEnum.No.getType())) {
            return OperationResult.buildFailureResult("该商户暂不支持开通提现费率");
        }
        return OperationResult.buildSuccessResult();
    }

    @Override
    public OperationResult openCashOutSave(@Valid UpmpBMchntFeeInfo entity) throws RedpException {
        UpmpUserInfoVO user = CommonUtils.getCurrentUser(upmpSysParamService);
        CommonUtils.validateUserInst(entity.getInstId(), user);
        Map<String, Object> result = Maps.newHashMap();

        if (FeeInputModeEnum.MANUAL_FIX.getType().equals(entity.getFeeInputMode())) {
            entity.setFeeRate(null);
            entity.setFeeFixedAmt(entity.getFeeCappingAmt());
            entity.setFeeCappingAmt(null);
        } else if (FeeInputModeEnum.MANUAL_RATE_MAX.getType().equals(entity.getFeeInputMode())) {
            entity.setFeeRate(entity.getFeeRate());
            entity.setFeeFixedAmt(null);
            entity.setFeeCappingAmt(entity.getFeeCappingAmt());
        } else if (FeeInputModeEnum.MANUAL_RATE.getType().equals(entity.getFeeInputMode())) {
            entity.setFeeRate(entity.getFeeRate());
            entity.setFeeFixedAmt(null);
            entity.setFeeCappingAmt(null);
        }
        MchntWithdrawManageRequest req = new MchntWithdrawManageRequest();
        req.setUserId(user.getId());
        CashWithdrawalFeeInfoBean bean = new CashWithdrawalFeeInfoBean();
        BeanUtils.copyProperties(entity, bean);
        bean.setFeeEffectiveDate(DateUtils.formatDate(new Date(), DateUtils.FORMAT_YYYYMMDD));
        bean.setFeeExpiryDate(BusinessContainer.doomsday);
        req.setMchntNo(entity.getMchntNo());
        req.setCashWithdrawalFeeInfoBean(bean);
        return bMchntFeeInfoService.mchntWithdrawManage(entity.getInstId(), req, bompMchntManageService, upmpPrivilegeCheckService, genMerOrder(entity.getInstId()), entity.getOptFlag());

    }

    @Override
    public OperationResult creditReport(OnlineVerificationVO entity) throws RedpException {
        UpmpUserInfoVO user = CommonUtils.getCurrentUser(upmpSysParamService);
        CommonUtils.validateUserInst(entity.getInstId(), user);
        CreditReportQueryRequest req = new CreditReportQueryRequest();
        BeanUtils.copyProperties(entity, req);
        req.setUserId(user.getId());
        String traceNo = genMerOrder(entity.getInstId());
        req.setHeader(CommonUtils.packageBompHeader(traceNo, BompTxnNumEnum.creditReportQuery.getType(), entity.getInstId(), null));

        Map<String, Object> result = Maps.newHashMap();
        try {
            log.info("法人行[" + user.getInstId() + "],用户标识[" + req.getUserId() + "],商户号[" + req.getMchntNo() + "]" + BompTxnNumEnum.creditReportQuery.getDesc() + "交易请求报文：" + JSON.toJSONString(req));
            Result<CreditReportQueryResponse> response = bompMchntManageService.creditReportQuery(req);
            log.info("法人行[" + user.getInstId() + "],用户标识[" + req.getUserId() + "],商户号[" + req.getMchntNo() + "]" + BompTxnNumEnum.creditReportQuery.getDesc() + "交易返回报文：" + JSON.toJSONString(response));
            if (response.isSuccess()) {
                CreditReportQueryResponse resp = response.getResult();
                result.put("respCode", resp.getRespCode());
                result.put("respMsg", resp.getRespDesc());
                result.put("onlineVerify", resp);
                // 返回码：00000000-进件成功，其他均视为失败
                if (BusinessContainer.BSPS_SUCCESS.equals(resp.getRespCode())) {
                    log.info("法人行[" + user.getInstId() + "],用户标识[" + req.getUserId() + "],商户号[" + req.getMchntNo() + "]" + BompTxnNumEnum.creditReportQuery.getDesc() + "交易成功");
                    return OperationResult.buildSuccessResult(BompTxnNumEnum.creditReportQuery.getDesc() + "交易成功", result);
                } else {
                    log.error("法人行[" + user.getInstId() + "],用户标识[" + req.getUserId() + "],商户号[" + req.getMchntNo() + "]" + BompTxnNumEnum.creditReportQuery.getDesc() + "交易失败");
                    return OperationResult.buildFailureResult(BompTxnNumEnum.creditReportQuery.getDesc() + "交易失败", result);
                }
            } else {
                result.put("resCode", BusinessContainer.ERROR);
                result.put("resMsg", BompTxnNumEnum.creditReportQuery.getDesc() + "没有获得返回报文");
                log.error("法人行[" + user.getInstId() + "],用户标识[" + req.getUserId() + "]" + BompTxnNumEnum.creditReportQuery.getDesc() + "交易没有获得返回信息");
                return OperationResult.buildFailureResult(BompTxnNumEnum.creditReportQuery.getDesc() + "交易失败", result);
            }
        } catch (Exception e) {
            // TODO: handle exception
            result.put("resCode", BusinessContainer.ERROR);
            result.put("resMsg", e.getMessage());
            log.error("法人行[" + user.getInstId() + "],用户标识[" + req.getUserId() + "]" + BompTxnNumEnum.creditReportQuery.getDesc() + "交易出现异常，异常信息：" + e.getMessage(), e);
//            throw new RedpException("商户编号为：[" + req.getMchntNo() + "]的商户，"+BompTxnNumEnum.mchntProdInfoManage.getDesc()+"交易出现异常",e);
            return OperationResult.buildFailureResult(BompTxnNumEnum.creditReportQuery.getDesc() + "交易失败", result);
        }
    }

    /**
     * ocr识别
     *
     * @param instId
     * @param user
     * @param req
     * @param traceNo
     * @return
     * @throws RedpException
     */
    @Override
    public OcrResponse ocrService(String instId, UpmpUserInfoVO user, OcrRequest req, String traceNo) throws RedpException {

        req.setHeader(CommonUtils.packageBompHeader(traceNo, BompTxnNumEnum.ocrService.getType(), instId, null));
        req.setUserId(user.getId());

        try {
            log.info("法人行[" + user.getInstId() + "],用户标识[" + req.getUserId() + "]" + BompTxnNumEnum.ocrService.getDesc() + "交易请求报文：" + JSON.toJSONString(req));

            Result<OcrResponse> response = bompMchntManageService.ocrService(req);
            log.info("法人行[" + user.getInstId() + "],用户标识[" + req.getUserId() + "]" + BompTxnNumEnum.ocrService.getDesc() + "交易返回报文：" + JSON.toJSONString(response));
            if (response.isSuccess()) {
                OcrResponse resp = response.getResult();
                // 返回码：00-成功，其他均视为失败
                if (BusinessContainer.BSPS_SUCCESS.equals(resp.getRespCode())) {
                    log.info("法人行[" + user.getInstId() + "],用户标识[" + req.getUserId() + "]" + BompTxnNumEnum.ocrService.getDesc() + "交易成功");
                    return resp;
                } else {
                    log.error("法人行[" + user.getInstId() + "],用户标识[" + req.getUserId() + "]" + BompTxnNumEnum.ocrService.getDesc() + "交易失败");
                    return null;
                }
            } else {
                log.error("法人行[" + user.getInstId() + "],用户标识[" + req.getUserId() + "]" + BompTxnNumEnum.ocrService.getDesc() + "交易没有获得返回信息");
                return null;
            }
        } catch (Exception e) {
            // TODO: handle exception
            log.error("法人行[" + user.getInstId() + "],用户标识[" + req.getUserId() + "]" + BompTxnNumEnum.ocrService.getDesc() + "交易出现异常，异常信息：" + e.getMessage(), e);
            throw new RedpException("法人行[" + user.getInstId() + "],用户标识[" + req.getUserId() + "]" + BompTxnNumEnum.ocrService.getDesc() + "交易出现异常，异常信息：" + e.getMessage());
        }
    }

    @Override
    public OperationResult onlineVerification(@Valid OnlineVerificationVO entity) throws RedpException {
        UpmpUserInfoVO user = CommonUtils.getCurrentUser(upmpSysParamService);
        CommonUtils.validateUserInst(entity.getInstId(), user);
        OnlineVerificationRequest req = new OnlineVerificationRequest();
        BeanUtils.copyProperties(entity, req);
        req.setUserId(user.getId());
        String traceNo = genMerOrder(entity.getInstId());
        String instId = entity.getInstId();
        req.setHeader(CommonUtils.packageBompHeader(traceNo, BompTxnNumEnum.onlineVerification.getType(), entity.getInstId(), null));
        Map<String, Object> result = Maps.newHashMap();
        try {
            log.info("法人行[" + instId + "],用户标识[" + req.getUserId() + "],商户号[" + req.getMchntNo() + "]" + BompTxnNumEnum.onlineVerification.getDesc() + "交易请求报文：" + JSON.toJSONString(req));
            Result<OnlineVerificationResponse> response = bompMchntManageService.onlineVerification(req);
            log.info("法人行[" + instId + "],用户标识[" + req.getUserId() + "],商户号[" + req.getMchntNo() + "]" + BompTxnNumEnum.onlineVerification.getDesc() + "交易返回报文：" + JSON.toJSONString(response));
            if (response.isSuccess()) {
                OnlineVerificationResponse resp = response.getResult();
                result.put("respCode", resp.getRespCode());
                result.put("respMsg", resp.getRespDesc());
                result.put("onlineVerify", resp);
                //将核查结果转换成中文含义
                if (Common.isNotBlank(resp.getCheckResult())) {
//                    result.put("checkResult",EnumUtils.getEnumDescriotionByValue(resp.getCheckResult(), BompOnlineVerifyResultEnum.class, "getType","getDesc").toString());
                    //为了测试强制将结果改成00，后期去掉
                    result.put("checkResult", BompOnlineVerifyResultEnum.EXITS_MATCH_PHOTO.getDesc());
                }
                // 返回码：00000000-进件成功，其他均视为失败
                if (BusinessContainer.BSPS_SUCCESS.equals(resp.getRespCode())) {

                    log.info("法人行[" + instId + "],用户标识[" + req.getUserId() + "],商户号[" + req.getMchntNo() + "]" + BompTxnNumEnum.onlineVerification.getDesc() + "交易成功");
                    return OperationResult.buildSuccessResult(BompTxnNumEnum.onlineVerification.getDesc() + "交易成功", result);
                } else {
                    log.error("法人行[" + instId + "],用户标识[" + req.getUserId() + "],商户号[" + req.getMchntNo() + "]" + BompTxnNumEnum.onlineVerification.getDesc() + "交易失败");
                    return OperationResult.buildFailureResult(BompTxnNumEnum.onlineVerification.getDesc() + "交易失败", result);
                }
            } else {
                result.put("resCode", BusinessContainer.ERROR);
                result.put("resMsg", BompTxnNumEnum.onlineVerification.getDesc() + "没有获得返回报文");
                log.error("法人行[" + instId + "],用户标识[" + req.getUserId() + "]" + BompTxnNumEnum.onlineVerification.getDesc() + "交易没有获得返回信息");
                return OperationResult.buildFailureResult(BompTxnNumEnum.onlineVerification.getDesc() + "交易失败", result);
            }
        } catch (Exception e) {
            // TODO: handle exception
            result.put("resCode", BusinessContainer.ERROR);
            result.put("resMsg", e.getMessage());
            log.error("法人行[" + instId + "],用户标识[" + req.getUserId() + "]" + BompTxnNumEnum.onlineVerification.getDesc() + "交易出现异常，异常信息：" + e.getMessage(), e);
//            throw new RedpException("商户编号为：[" + req.getMchntNo() + "]的商户，"+BompTxnNumEnum.mchntProdInfoManage.getDesc()+"交易出现异常",e);
            return OperationResult.buildFailureResult(BompTxnNumEnum.onlineVerification.getDesc() + "交易失败", result);
        }
    }

    @Override
    public OperationResult thirdEntry(@Valid InstMchntRegisterVO entity, String opr) throws RedpException {
        opr = opr == null ? "0" : opr;
        UpmpUserInfoVO user = CommonUtils.getCurrentUser(upmpSysParamService);
        if (opr.equals(BusinessContainer.MCHNT_REG_OPR)) {

            log.info("开始第三方进件！");
            InstMchntRegisterRequest req = new InstMchntRegisterRequest();
            BeanUtils.copyProperties(entity, req);
            req.setOprType("0");
            req.setUserId(user.getId());

            return thirdEntry(entity.getInstId(), req, genMerOrder(entity.getInstId()));
        } else if (opr.equals(BusinessContainer.MCHNT_QRY_OPR)) {
            InstMchntQueryRequest req = new InstMchntQueryRequest();
            log.info("开始第三方进件查询！");
            BeanUtils.copyProperties(entity, req);
            req.setUserId(user.getId());
            return thirdEntryQuery(entity.getInstId(), req, genMerOrder(entity.getInstId()));

        } else {
            return new OperationResult(OperationResult.OPERATION_RESULT_TYPE.failure, "不支持的交易类型");
        }
    }

    @Override
    public OperationResult thirdEntry(String instId, InstMchntRegisterRequest req, String traceNo) {

        req.setHeader(CommonUtils.packageBompHeader(traceNo, BompTxnNumEnum.instMchntRegister.getType(), instId, null));
        Map<String, Object> result = Maps.newHashMap();
        try {

            log.info("法人行[" + instId + "],用户标识[" + req.getUserId() + "]" + BompTxnNumEnum.instMchntRegister.getDesc() + "交易请求报文：" + JSON.toJSONString(req));

            Result<InstMchntRegisterResponse> response = bompThirdMchntEntryService.instMchntRegister(req);

            log.info("法人行[" + instId + "],用户标识[" + req.getUserId() + "]" + BompTxnNumEnum.instMchntRegister.getDesc() + "交易返回报文：" + JSON.toJSONString(response));
            if (response.isSuccess()) {
                InstMchntRegisterResponse resp = response.getResult();
                // 返回码：00000000-进件成功，其他均视为失败
                if (BusinessContainer.BSPS_SUCCESS.equals(resp.getRespCode())) {
                    result.put("respCode", resp.getRespCode());
                    result.put("respMsg", resp.getRespDesc());
                    log.info("法人行[" + instId + "],用户标识[" + req.getUserId() + "]" + BompTxnNumEnum.instMchntRegister.getDesc() + "交易成功");
                    return OperationResult.buildSuccessResult(BompTxnNumEnum.instMchntRegister.getDesc() + "交易成功", result);
                } else {
                    result.put("respCode", resp.getRespCode());
                    result.put("respMsg", resp.getRespDesc());
                    return OperationResult.buildFailureResult(BompTxnNumEnum.instMchntRegister.getDesc() + "交易失败", result);
                }
            } else {
                result.put("resCode", BusinessContainer.ERROR);
                result.put("resMsg", BompTxnNumEnum.instMchntRegister.getDesc() + "没有获得返回报文");
                log.error("法人行[" + instId + "],用户标识[" + req.getUserId() + "]" + BompTxnNumEnum.instMchntRegister.getDesc() + "交易没有获得返回信息");
                return OperationResult.buildFailureResult(BompTxnNumEnum.instMchntRegister.getDesc() + "交易失败", result);
            }
        } catch (Exception e) {
            // TODO: handle exception
            result.put("resCode", BusinessContainer.ERROR);
            result.put("resMsg", e.getMessage());
            log.error("法人行[" + instId + "],用户标识[" + req.getUserId() + "]" + BompTxnNumEnum.instMchntRegister.getDesc() + "交易出现异常，异常信息：" + e.getMessage(), e);
//            throw new RedpException("商户编号为：[" + req.getMchntNo() + "]的商户，"+BompTxnNumEnum.mchntProdInfoManage.getDesc()+"交易出现异常",e);
            return OperationResult.buildFailureResult(BompTxnNumEnum.instMchntRegister.getDesc() + "交易失败", result);
        }
    }

    @Override
    public OperationResult thirdEntryQuery(String instId, InstMchntQueryRequest req, String traceNo) {

        req.setHeader(CommonUtils.packageBompHeader(traceNo, BompTxnNumEnum.instMchntQuery.getType(), instId, null));
        Map<String, Object> result = Maps.newHashMap();
        try {

            log.info("法人行[" + instId + "],用户标识[" + req.getUserId() + "]" + BompTxnNumEnum.instMchntQuery.getDesc() + "交易请求报文：" + JSON.toJSONString(req));

            Result<InstMchntQueryResponse> response = bompThirdMchntEntryService.instMchntQuery(req);

            log.info("法人行[" + instId + "],用户标识[" + req.getUserId() + "]" + BompTxnNumEnum.instMchntQuery.getDesc() + "交易返回报文：" + JSON.toJSONString(response));
            if (response.isSuccess()) {
                InstMchntQueryResponse resp = response.getResult();
                // 返回码：00000000-进件成功，其他均视为失败
                if (BusinessContainer.BSPS_SUCCESS.equals(resp.getRespCode())) {
                    log.info("法人行[" + instId + "],用户标识[" + req.getUserId() + "]" + BompTxnNumEnum.instMchntQuery.getDesc() + "交易成功");
                    return OperationResult.buildSuccessResult(BompTxnNumEnum.instMchntQuery.getDesc() + "交易成功", resp);
                } else {
                    result.put("respCode", resp.getRespCode());
                    result.put("respMsg", resp.getRespDesc());
                    return OperationResult.buildFailureResult(BompTxnNumEnum.instMchntQuery.getDesc() + "交易失败", result);
                }
            } else {
                result.put("resCode", BusinessContainer.ERROR);
                result.put("resMsg", BompTxnNumEnum.instMchntQuery.getDesc() + "没有获得返回报文");
                log.error("法人行[" + instId + "],用户标识[" + req.getUserId() + "]" + BompTxnNumEnum.instMchntQuery.getDesc() + "交易没有获得返回信息");
                return OperationResult.buildFailureResult(BompTxnNumEnum.instMchntQuery.getDesc() + "交易失败", result);
            }
        } catch (Exception e) {
            // TODO: handle exception
            result.put("resCode", BusinessContainer.ERROR);
            result.put("resMsg", e.getMessage());
            log.error("法人行[" + instId + "],用户标识[" + req.getUserId() + "]" + BompTxnNumEnum.instMchntQuery.getDesc() + "交易出现异常，异常信息：" + e.getMessage(), e);
//            throw new RedpException("商户编号为：[" + req.getMchntNo() + "]的商户，"+BompTxnNumEnum.mchntProdInfoManage.getDesc()+"交易出现异常",e);
            return OperationResult.buildFailureResult(BompTxnNumEnum.instMchntQuery.getDesc() + "交易失败", result);
        }
    }

    @Override
    public OperationResult cancelQuery(String instId, String mchntNo) throws RedpException {
        UpmpUserInfoVO user = CommonUtils.getCurrentUser(upmpSysParamService);
        log.info("开始商户终端及二维码数量查询！");
        TermAndQrcodeNumQueryRequest req = new TermAndQrcodeNumQueryRequest();
        req.setMchntNo(mchntNo);
        req.setStatus(BizDataStatusEnum.STATUS_NORMAL.getType());
        req.setUserId(user.getId());
        TermAndQrcodeNumQueryResponse resp = termAndQrcodeNumQuery(instId, req, genMerOrder(instId));
        if (Common.isNotBlank(resp)) {
            return OperationResult.buildSuccessResult(resp);
        } else {
            return OperationResult.buildFailureResult("法人行[" + instId + "],用户标识[" + req.getUserId() + "]" + BompTxnNumEnum.termAndQrcodeNumQuery.getDesc() + "交易失败");
        }
    }

    /**
     * 商户终端及二维码数量查询
     *
     * @param instId
     * @param req
     * @param traceNo
     * @return
     * @throws RedpException
     */
    public TermAndQrcodeNumQueryResponse termAndQrcodeNumQuery(String instId, TermAndQrcodeNumQueryRequest req, String traceNo) throws RedpException {

        req.setHeader(CommonUtils.packageBompHeader(traceNo, BompTxnNumEnum.termAndQrcodeNumQuery.getType(), instId, null));
        try {
            log.info("法人行[" + instId + "],用户标识[" + req.getUserId() + "]" + BompTxnNumEnum.termAndQrcodeNumQuery.getDesc() + "交易请求报文：" + JSON.toJSONString(req));

            Result<TermAndQrcodeNumQueryResponse> response = bompMchntQueryService.termAndQrcodeNumQuery(req);
            log.info("法人行[" + instId + "],用户标识[" + req.getUserId() + "]" + BompTxnNumEnum.termAndQrcodeNumQuery.getDesc() + "交易返回报文：" + JSON.toJSONString(response));
            if (response.isSuccess()) {
                TermAndQrcodeNumQueryResponse resp = response.getResult();
                // 返回码：00000000-进件成功，其他均视为失败
                if (BusinessContainer.BSPS_SUCCESS.equals(resp.getRespCode())) {
                    log.info("法人行[" + instId + "],用户标识[" + req.getUserId() + "]" + BompTxnNumEnum.termAndQrcodeNumQuery.getDesc() + "交易成功");
                    return resp;
                } else {
                    log.error("法人行[" + instId + "],用户标识[" + req.getUserId() + "]" + BompTxnNumEnum.termAndQrcodeNumQuery.getDesc() + "交易失败");
                    return null;
                }
            } else {
                log.error("法人行[" + instId + "],用户标识[" + req.getUserId() + "]" + BompTxnNumEnum.termAndQrcodeNumQuery.getDesc() + "交易没有获得返回信息");
                return null;
            }
        } catch (Exception e) {
            // TODO: handle exception
            log.error("法人行[" + instId + "],用户标识[" + req.getUserId() + "]" + BompTxnNumEnum.termAndQrcodeNumQuery.getDesc() + "交易出现异常，异常信息：" + e.getMessage(), e);
            throw new RedpException("法人行[" + instId + "],用户标识[" + req.getUserId() + "]" + BompTxnNumEnum.termAndQrcodeNumQuery.getDesc() + "交易出现异常，异常信息：" + e.getMessage());
        }
    }

    @Override
    public OperationResult instMchntBlacklist(String instId, String mchntNo, String mchntName) throws RedpException {
        UpmpBMchntBlacklistInfo mchntblacklistinfo = new UpmpBMchntBlacklistInfo();
        UpmpUserInfoVO user = CommonUtils.getCurrentUser(upmpSysParamService);
        mchntblacklistinfo.setMchntNo(mchntNo);
        mchntblacklistinfo.setMchntName(mchntName);
        mchntblacklistinfo.setInstId(instId);
        mchntblacklistinfo.setValidStatus("01");
        mchntblacklistinfo.setDataSources("01");
        mchntblacklistinfo.setMchntBlacklistStatus("01");
        mchntblacklistinfo.setAuditStatus("02");
        mchntblacklistinfo.setCrtOrgId(user.getOrgCode());
        String oprMenuId = "1";
        String oprMenuName = "风险管理:商户黑名单管理";
        Map<String, Object> result = Maps.newHashMap();
        SimpleDateFormat fmtdt = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
        String lastUpddt = fmtdt.format(new Date());
        mchntblacklistinfo.setMchntBlacklistStatus(BizDataStatusEnum.STATUS_NORMAL.getType());
        mchntblacklistinfo.setAuditStatus(BizDataAuditStatusEnum.AUDIT_STATUS_ADD_PASS.getType());
        mchntBlackListInfoService.save(mchntblacklistinfo);

        bizHisService.saveBizHisNew(mchntblacklistinfo, mchntblacklistinfo, user, instId, BizOprEnum.OPR_ADD.getType(), DateUtil.getDateFormat(new Date(), DateUtil.FULL_TIME_WITH_MILL_SPLIT_PATTERN)
                , oprMenuId, oprMenuName, String.valueOf(mchntblacklistinfo.getId()), mchntblacklistinfo.getMchntNo(), mchntblacklistinfo.getMchntName(), null);
        result.put("id", mchntblacklistinfo.getId());
        return OperationResult.buildSuccessResult("数据保存处理完成", result);
    }

    @Override
    public OperationResult accSign(String instId,
                                   String acctNo, String mchntNo) throws RedpException {
        UpmpUserInfoVO user = CommonUtils.getCurrentUser(upmpSysParamService);
        CommonUtils.validateUserInst(instId, user);
        //1、调用系统参数查询接口  查询是否需要进行核心签约
        ParamQueryRequest req = new ParamQueryRequest();
        req.setUserId(user.getId());
        req.setParamKey(ParamQueryKeyEnum.CORE_ACCT_SIGN.getType());
        req.setParamType(BusinessContainer.MCMP_TO_BOMP_PARAM_TYPE);
        ParamQueryResponse paramQueryResponse = paramQuery(instId, req, genMerOrder(instId));
        List<SysParamBean> sysParamList = paramQueryResponse.getSysParamList();
        String paramValue = "";
        if (Common.isNotBlank(sysParamList)) {
            paramValue = sysParamList.get(0).getParamValue();
        }
        if (!paramValue.equals("Y")) {
            log.error("不支持的操作，法人行[{" + user.getInstId() + "}]不需要进行核心签约。");
            throw new RedpException("不支持的操作，法人行[" + user.getInstId() + "]不需要进行核心签约。");
        }
        return settleAccountSign(user, genMerOrder(instId), acctNo, mchntNo,instId);
    }

    public OperationResult settleAccountSign(UpmpUserInfoVO user, String traceNo, String acctNo, String mchntNo,String instId) {
        SettleAccountSignRequest req = new SettleAccountSignRequest();
        req.setHeader(CommonUtils.packageBompHeader(traceNo, BompTxnNumEnum.settleAccountSign.getType(), instId, null));
        req.setUserId(user.getId());
        req.setAcctNo(acctNo);
        req.setMchntNo(mchntNo);

        log.info("商户编号为：" + mchntNo + "的商户，" + BompTxnNumEnum.settleAccountSign.getDesc() + "请求报文：" + JSON.toJSONString(req));

        Map<String, Object> result = Maps.newHashMap();
        try {
            Result<SettleAccountSignResponse> response = bompMchntManageService.settleAccountSign(req);


            log.info("商户编号为：" + mchntNo + "的商户，" + BompTxnNumEnum.settleAccountSign.getDesc() + "交易返回报文：" + JSON.toJSONString(response));

            if (response.isSuccess()) {
                SettleAccountSignResponse resp = response.getResult();
                // 返回码：00000000-进件成功，其他均视为失败
                if (BusinessContainer.BSPS_SUCCESS.equals(resp.getRespCode())) {
                    result.put("respCode", resp.getRespCode());
                    result.put("respMsg", resp.getRespDesc());
                    log.info("商户编号为：" + mchntNo + "的商户，" + BompTxnNumEnum.settleAccountSign.getDesc() + "账户状态正常");
                    return OperationResult.buildSuccessResult(BompTxnNumEnum.settleAccountSign.getDesc() + "交易成功", result);
                } else {
                    result.put("respCode", resp.getRespCode());
                    result.put("respMsg", resp.getRespDesc());
                    return OperationResult.buildFailureResult(BompTxnNumEnum.settleAccountSign.getDesc() + "失败", result);
                }
            } else {
                result.put("resCode", BusinessContainer.ERROR);
                result.put("resMsg", BompTxnNumEnum.settleAccountSign.getDesc() + "没有获得返回报文");
                log.error("商户编号为：" + mchntNo + "的商户，" + BompTxnNumEnum.settleAccountSign.getDesc() + "交易没有获得返回信息");
                return OperationResult.buildFailureResult(BompTxnNumEnum.settleAccountSign.getDesc() + "失败", result);
            }
        } catch (Exception e) {
            // TODO: handle exception
            result.put("resCode", BusinessContainer.ERROR);
            result.put("resMsg", e.getMessage());
            log.error("商户编号为：" + mchntNo + "的商户，" + BompTxnNumEnum.settleAccountSign.getDesc() + "交易出现异常，异常信息：" + e.getMessage(), e);
            return OperationResult.buildFailureResult(BompTxnNumEnum.settleAccountSign.getDesc() + "失败", result);
        }
    }

    @Override
    public OperationResult mchntType(String instId, String optFlag,
                                     String mchntNo, String refuseReason) throws RedpException {
        UpmpUserInfoVO user = CommonUtils.getCurrentUser(upmpSysParamService);
        CommonUtils.validateUserInst(instId, user);


        MchntBaseInfoQueryResponse mchntBase = mchntBaseInfoQuery(instId, user, genMerOrder(instId), mchntNo, "", BompQueryTypeEnum.REAL, bompMchntQueryService);
        MchntProdInfoManageRequest req = new MchntProdInfoManageRequest();
        req.setUserId(user.getId());
        req.setMchntNo(mchntNo);
        String manageOprType = "";
        if (PageOptFlagEnum.OPT_FLAG_ADD.getType().equals(optFlag)) {
            manageOprType = "11";
        } else if (PageOptFlagEnum.OPT_FLAG_UPDATE.getType().equals(optFlag)) {
            manageOprType = "12";
        } else if (PageOptFlagEnum.OPT_FLAG_CHECK.getType().equals(optFlag)
                || PageOptFlagEnum.OPT_FLAG_PASS.getType().equals(optFlag)
                || PageOptFlagEnum.OPT_FLAG_REJECT.getType().equals(optFlag)) {
            manageOprType = "03";
            if (PageOptFlagEnum.OPT_FLAG_PASS.getType().equals(optFlag)) {
                req.setCheckStatus("01");
            } else if (PageOptFlagEnum.OPT_FLAG_REJECT.getType().equals(optFlag)) {
                req.setCheckStatus("02");
            }
        }
        if (Common.isNotBlank(refuseReason)) {
            req.setAuditRefuseReason(refuseReason);
        }
        OperationResult operationResult = bMchntProdInfoService.mchntProdSave(instId, req, bompMchntManageService, upmpPrivilegeCheckService, genMerOrder(instId), optFlag, manageOprType);
        if (operationResult.getCode().equals("100000") && PageOptFlagEnum.OPT_FLAG_PASS.getType().equals(optFlag)) {
            if (mchntBase.getAuditStatus().equals("11")) {
                operationResult.setCode("111111");
            }
            Map<String, Object> data = (Map<String, Object>) operationResult.getData();
            data.put("MchntName", mchntBase.getMchntBaseInfo().getMchntName());
            data.put("MchntNo", mchntBase.getMchntBaseInfo().getMchntNo());
            data.put("instId", instId);
        }
        return operationResult;
    }

    @Override
    public UpmpBMchntBaseInfo queryMchntNo(String instId, String mchntNo) {
        LambdaQueryWrapper<UpmpBMchntBaseInfo> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(UpmpBMchntBaseInfo::getMchntType, "10");
        wrapper.eq(UpmpBMchntBaseInfo::getInstId, instId);
        wrapper.eq(UpmpBMchntBaseInfo::getMchntNo, mchntNo);
        return this.getOne(wrapper);
    }

    @Override
    public Map<String, Object> agentMchntSelect2List(String instId,String agentMchntNo, QueryRequest request) throws RedpException {
        AgentMchntListQueryRequest req = new AgentMchntListQueryRequest();
        UpmpUserInfoVO user = CommonUtils.getCurrentUser(upmpSysParamService);
        int pageIndex = Common.isBlank(request.getPageNum()) ? 1 : request.getPageNum();
        int pageSize = Common.isBlank(request.getPageSize()) ? Integer.parseInt(BusinessContainer.ECP_PAGE_MAXROWS) : request.getPageSize();
        req.setPageIndex(pageIndex - 1);//联机页码从0开始，select2页码从1开始
        req.setPageSize(pageSize);
        req.setAgentMchntNo(agentMchntNo);
        req.setAgentMchntName(agentMchntNo);
        req.setUserId(user.getId());

        AgentMchntListQueryResponse resp = agentMchntListQuery(instId, user, req, bompMchntQueryService, genMerOrder(instId));

        Map<String, Object> maps = new HashMap<String, Object>();
        List<Object> rst = new ArrayList<Object>();
        if (Common.isNotBlank(resp)) {
            List<AgentMchntInfoBean> list = Lists.newArrayList();
            if (Common.isNotBlank(resp) && CollectionUtils.isNotEmpty(resp.getAgentMchntInfoList())) {
                list = resp.getAgentMchntInfoList();
            }

            if (CollectionUtils.isNotEmpty(list)) {
                Map<String, String> map = new HashMap<String, String>();
                for (AgentMchntInfoBean mchnt : list) {

                    map = new HashMap<String, String>();
                    map.put("id", mchnt.getAgentMchntNo());
                    map.put("name", mchnt.getAgentMchntName());
                    rst.add(map);
                }
                maps.put("rows", rst);
                maps.put("total", resp.getTotalRows());
                if (Integer.valueOf(pageIndex) * Integer.valueOf(pageSize) > resp.getTotalRows()) {
                    maps.put("more", false);
                } else {
                    maps.put("more", true);
                }
            } else {
                maps.put("rows", rst);
            }
        } else {
            maps.put("rows", rst);
        }
        return maps;
    }

    @Override
    public Map<String, Object> industryInfoSelect2List(String q, QueryRequest request) throws RedpException {
        //常用行业类别
        String[] codes = {"5812就餐场所和餐馆", "7011住宿服务", "7298保健、美容及洗浴服务", "7999未列入其他代码的娱乐服务", "5039建筑装饰材料批发", "5065电器零件与通信器材批发", "5072五金批发", "5137服装、化妆品、卫生用品批发", "5998其他批发商", "4812通讯设备销售", "5251五金商店", "5311百货商店", "5331各类杂货店、便利店", "5399未列入其他代码的综合零售服务", "5499未列入其他代码的食品商店", "5621女装商店", "5732电子设备商店"};
        if (null == q) {
            return null;
        }
        IndustryInfoQueryRequest req = new IndustryInfoQueryRequest();
        q = q.replaceAll("&amp;", "&");
        UpmpUserInfoVO user = CommonUtils.getCurrentUser(upmpSysParamService);
        String code = "";
        String name = "";
        String[] param = q.split("&");
        if (null != param && param.length > 0) {
            code = param[0];
            name = param[0];
        }
        String instId = "";
        if (null != param && param.length > 1) {
            if (Common.isNotBlank(param[1])) {
                instId = param[1];
            }
        }
        //设置经营范围值
        if (null != param && param.length > 2) {
            if (Common.isNotBlank(param[2])) {
                req.setManagementScope(param[2]);
            }
        }
        int pageIndex = Common.isBlank(request.getPageNum()) ? 1 : request.getPageNum();
        int pageSize = Common.isBlank(request.getPageSize()) ? Integer.parseInt(BusinessContainer.ECP_PAGE_MAXROWS) : request.getPageSize();
        req.setPageIndex(pageIndex - 1);//联机页码从0开始，select2页码从1开始
        req.setPageSize(pageSize);
        req.setIndustryCode(code);
        req.setIndustryName(name);
        req.setUserId(user.getId());
        String traceNo = genMerOrder(instId);
        IndustryInfoQueryResponse resp = industryInfoQuery(instId, user, req, bompPublicQueryService, traceNo);


        Map<String, Object> maps = new HashMap<String, Object>();
        if (Common.isNotBlank(resp)) {
            List<IndustryInfoBean> list = Lists.newArrayList();
            String substring1 = "";
            if (req.getManagementScope().equals("11") && pageIndex == 1) {
                for (int i = 0; i < 4; i++) {
                    IndustryInfoBean industryinfobean = new IndustryInfoBean();
                    String code1 = codes[i];
                    industryinfobean.setIndustryCode(code1.substring(0, 4));
                    industryinfobean.setIndustryName(code1.substring(4));
                    list.add(industryinfobean);
                }
            }
            if (req.getManagementScope().equals("13") && pageIndex == 1) {
                for (int i = 4; i < 9; i++) {
                    IndustryInfoBean industryinfobean = new IndustryInfoBean();
                    String code1 = codes[i];
                    industryinfobean.setIndustryCode(code1.substring(0, 4));
                    industryinfobean.setIndustryName(code1.substring(4));
                    list.add(industryinfobean);
                }
            }
            if (req.getManagementScope().equals("14") && pageIndex == 1) {
                for (int i = 9; i < codes.length; i++) {
                    IndustryInfoBean industryinfobean = new IndustryInfoBean();
                    String code1 = codes[i];
                    industryinfobean.setIndustryCode(code1.substring(0, 4));
                    industryinfobean.setIndustryName(code1.substring(4));
                    list.add(industryinfobean);
                }
            }
            if (Common.isNotBlank(resp) && CollectionUtils.isNotEmpty(resp.getIndustrylInfoList())) {
                List<IndustryInfoBean> industrylInfoList = Lists.newArrayList();
                List<IndustryInfoBean> industrylInfoList2 = resp.getIndustrylInfoList();
                if (CollectionUtils.isNotEmpty(list)) {
                    for (IndustryInfoBean industryinfobean : list) {
                        industrylInfoList.add(industryinfobean);
                    }
                }
                for (IndustryInfoBean industryinfobean : industrylInfoList2) {
                    if (req.getManagementScope().equals("11")) {
                        if (!industryinfobean.getIndustryCode().equals("5812") && !industryinfobean.getIndustryCode().equals("7011") && !industryinfobean.getIndustryCode().equals("7298") && !industryinfobean.getIndustryCode().equals("7999")) {
                            industrylInfoList.add(industryinfobean);
                        }
                    } else if (req.getManagementScope().equals("13")) {
                        if (!industryinfobean.getIndustryCode().equals("5039") && !industryinfobean.getIndustryCode().equals("5045") && !industryinfobean.getIndustryCode().equals("5065") && !industryinfobean.getIndustryCode().equals("5072") && !industryinfobean.getIndustryCode().equals("5137") && !industryinfobean.getIndustryCode().equals("5998")) {
                            industrylInfoList.add(industryinfobean);
                        }
                    }
                    if (req.getManagementScope().equals("14")) {
                        if (!industryinfobean.getIndustryCode().equals("4812") && !industryinfobean.getIndustryCode().equals("5251") && !industryinfobean.getIndustryCode().equals("5311") && !industryinfobean.getIndustryCode().equals("5399") && !industryinfobean.getIndustryCode().equals("5499") && !industryinfobean.getIndustryCode().equals("5621") && !industryinfobean.getIndustryCode().equals("5732")) {
                            industrylInfoList.add(industryinfobean);
                        }
                    } else {
                        industrylInfoList.add(industryinfobean);
                    }
                }

                if (CollectionUtils.isNotEmpty(industrylInfoList)) {
                    Map<String, String> map = new HashMap<String, String>();
                    List<Object> rst = new ArrayList<Object>();
                    for (IndustryInfoBean mchnt : industrylInfoList) {

                        map = new HashMap<String, String>();
                        map.put("id", mchnt.getIndustryCode());
                        map.put("name", mchnt.getIndustryName());
                        // map.put("belorgname",mc.getBelOrgName());
                        rst.add(map);
                    }
                    maps.put("results", rst);
                    maps.put("total", resp.getTotalRows());
                    if (Integer.valueOf(pageIndex) * Integer.valueOf(pageSize) > resp.getTotalRows()) {
                        maps.put("more", false);
                    } else {
                        maps.put("more", true);
                    }
                }
            }
        }
            return maps;
    }

    @Override
    public Map<String, Object> mchntAreaSelect2List(String q, QueryRequest request) throws RedpException {
        MchntAreaListQueryRequest req = new MchntAreaListQueryRequest();
        UpmpUserInfoVO user = CommonUtils.getCurrentUser(upmpSysParamService);
        if (null == q) {
            return null;
        }
        q = q.replaceAll("&amp;", "&");
        String code = "";
        String name = "";
        String[] param = q.split("&");
        if (Common.isNotBlank(param) && param.length > 0) {
            code = param[0];
            name = param[0];
        }
        String instId = "";
        if (Common.isNotBlank(param) && param.length > 1) {
            if (Common.isNotBlank(param[1])) {
                instId = param[1];
            }
        }
        String signInstId = "";
        if (Common.isNotBlank(param) && param.length > 2) {
            if (Common.isNotBlank(param[2])) {
                signInstId = param[2];
            }
        }
        int pageIndex = Common.isBlank(request.getPageNum()) ? 1 : request.getPageNum();
        int pageSize = Common.isBlank(request.getPageSize()) ? Integer.parseInt(BusinessContainer.ECP_PAGE_MAXROWS) : request.getPageSize();
        String traceNo = genMerOrder(instId);

        req.setMchntArea(code);
        req.setMchntAreaName(name);
        req.setPageIndex(pageIndex - 1);//联机页码从0开始，select2页码从1开始
        req.setPageSize(pageSize);
        req.setUserId(user.getId());
        req.setSignInstId(signInstId);
        MchntAreaListQueryResponse resp = mchntAreaListQuery(instId, user, req, bompMchntQueryService, traceNo);


        Map<String, Object> maps = new HashMap<String, Object>();
        if (Common.isNotBlank(resp)) {
            List<MchntAreaInfoBean> list = Lists.newArrayList();
            if (Common.isNotBlank(resp) && CollectionUtils.isNotEmpty(resp.getMchntAreaInfoList())) {
                list = resp.getMchntAreaInfoList();
            }

            List<Object> rst = new ArrayList<Object>();
            if (pageIndex == 1) {
                Map<String, String> map1 = new HashMap<String, String>();
                map1.put("id", "");
                map1.put("name", "请选择...");
                rst.add(map1);
            }

            if (CollectionUtils.isNotEmpty(list)) {
                Map<String, String> map = new HashMap<String, String>();
                for (MchntAreaInfoBean area : list) {

                    map = new HashMap<String, String>();
                    map.put("id", area.getMchntArea());
                    map.put("name", area.getMchntAreaName());
                    // map.put("belorgname",mc.getBelOrgName());
                    rst.add(map);
                }
                maps.put("results", rst);
                maps.put("total", resp.getTotalRows());
                if (Integer.valueOf(pageIndex) * Integer.valueOf(pageSize) > resp.getTotalRows()) {
                    maps.put("more", false);
                } else {
                    maps.put("more", true);
                }
            }
        }
        return maps;
    }

    @Override
    public Map<String, Object> mchntLevelSelect2List(String q, QueryRequest request) throws RedpException {
        MchntLevelListQueryRequest req = new MchntLevelListQueryRequest();
        UpmpUserInfoVO user = CommonUtils.getCurrentUser(upmpSysParamService);
        if (null == q) {
            return null;
        }
        q = q.replaceAll("&amp;", "&");
        String code = "";
        String name = "";
        String[] param = q.split("&");
        if (null != param && param.length > 0) {
            code = param[0];
            name = param[0];
        }
        String instId = "";
        if (null != param && param.length > 1) {
            if (Common.isNotBlank(param[1])) {
                instId = param[1];
            }
        }
        String mchntType = "";
        if (null != param && param.length > 2) {
            if (Common.isNotBlank(param[2])) {
                mchntType = param[2];
            }
        }
        int pageIndex = Common.isBlank(request.getPageNum()) ? 1 : request.getPageNum();
        int pageSize = Common.isBlank(request.getPageSize()) ? Integer.parseInt(BusinessContainer.ECP_PAGE_MAXROWS) : request.getPageSize();
        String traceNo = genMerOrder(instId);

        req.setMchntLevel(code);
        req.setMchntLevelName(name);
        req.setPageIndex(pageIndex - 1);//联机页码从0开始，select2页码从1开始
        req.setPageSize(pageSize);
        req.setUserId(user.getId());
        if (MchntTypeEnum.SMALL_MICRO_MCHNT.getType().equals(mchntType)) {
            req.setPageIndex(-1);
            req.setPageSize(-1);
        }
        MchntLevelListQueryResponse resp = mchntLevelListQuery(instId, user, req, bompMchntQueryService, traceNo);


        Map<String, Object> maps = new HashMap<String, Object>();
        if (Common.isNotBlank(resp)) {
            List<MchntLevelInfoBean> list = Lists.newArrayList();
            if (Common.isNotBlank(resp) && CollectionUtils.isNotEmpty(resp.getMchntLevelInfoList())) {
                list = resp.getMchntLevelInfoList();
            }

            if (CollectionUtils.isNotEmpty(list)) {
                Map<String, String> map = new HashMap<String, String>();
                List<Object> rst = new ArrayList<Object>();
                for (MchntLevelInfoBean area : list) {

                    map = new HashMap<String, String>();
                    map.put("id", area.getMchntLevel());
                    map.put("name", area.getMchntLevelName());
                    // map.put("belorgname",mc.getBelOrgName());
                    String mchntlevel = "ML" + instId + "099";
                    if (MchntTypeEnum.SMALL_MICRO_MCHNT.getType().equals(mchntType)) {
                        //小微商户
                        if (mchntlevel.equals(area.getMchntLevel()) || BusinessContainer.XW_MCHNT_LEVEL_OLD.equals(area.getMchntLevel())) {
                            rst.add(map);
                        }
                    } else {
                        if (!mchntlevel.equals(area.getMchntLevel()) && !BusinessContainer.XW_MCHNT_LEVEL_OLD.equals(area.getMchntLevel())) {
                            rst.add(map);
                        }
                    }
                }
                maps.put("results", rst);
                maps.put("total", resp.getTotalRows());
                if (Integer.valueOf(pageIndex) * Integer.valueOf(pageSize) > resp.getTotalRows()) {
                    maps.put("more", false);
                } else {
                    maps.put("more", true);
                }
            }
        }
        return maps;
    }

    @Override
    public Map<String, Object> platMchntSelect2List(String q, QueryRequest request) throws RedpException {
        PlatMchntListQueryRequest req = new PlatMchntListQueryRequest();
        UpmpUserInfoVO user = CommonUtils.getCurrentUser(upmpSysParamService);
        if (null == q) {
            return null;
        }
        q = q.replaceAll("&amp;", "&");
        String code = "";
        String name = "";
        String[] param = q.split("&");
        if (null != param && param.length > 0) {
            code = param[0];
            name = param[0];
        }
        String instId = "";
        if (null != param && param.length > 1) {
            if (Common.isNotBlank(param[1])) {
                instId = param[1];
            }
        }
        int pageIndex = Common.isBlank(request.getPageNum()) ? 1 : request.getPageNum();
        int pageSize = Common.isBlank(request.getPageSize()) ? Integer.parseInt(BusinessContainer.ECP_PAGE_MAXROWS) : request.getPageSize();
        String traceNo = genMerOrder(instId);

        req.setPageIndex(pageIndex - 1);//联机页码从0开始，select2页码从1开始
        req.setPageSize(pageSize);
        req.setPlatMchntNo(code);
        req.setPlatMchntName(name);
        req.setUserId(user.getId());

        PlatMchntListQueryResponse resp = platMchntListQuery(instId, user, req, bompMchntQueryService, traceNo);


        Map<String, Object> maps = new HashMap<String, Object>();
        if (Common.isNotBlank(resp)) {
            List<PlatMchntInfoBean> list = Lists.newArrayList();
            if (Common.isNotBlank(resp) && CollectionUtils.isNotEmpty(resp.getPlatMchntInfoList())) {
                list = resp.getPlatMchntInfoList();
            }
            List<Object> rst = new ArrayList<Object>();
            if (pageIndex == 1) {
                Map<String, String> map1 = new HashMap<String, String>();
                map1.put("id", "");
                map1.put("name", "请选择...");
                rst.add(map1);
            }

            if (CollectionUtils.isNotEmpty(list)) {
                Map<String, String> map = new HashMap<String, String>();

                for (PlatMchntInfoBean mchnt : list) {

                    map = new HashMap<String, String>();
                    map.put("id", mchnt.getPlatMchntNo());
                    map.put("name", mchnt.getPlatMchntName());
                    // map.put("belorgname",mc.getBelOrgName());
                    rst.add(map);
                }
                maps.put("results", rst);
                maps.put("total", resp.getTotalRows());
                if (Integer.valueOf(pageIndex) * Integer.valueOf(pageSize) > resp.getTotalRows()) {
                    maps.put("more", false);
                } else {
                    maps.put("more", true);
                }
            }
        }
        return maps;
    }


    @Override
    public Map newMchntCount(String userId) {
        Map<String, Object> result = Maps.newHashMap();
        UpmpUserInfo user = upmpUserInfoService.findById(userId);
        String yestdate = DateUtils.formatDate(DateUtils.nDaysAgo(1, new Date()), "yyyy-MM-dd");
        String userOrgCodes = user.getOrgCode();
        result.put("count", this.baseMapper.getCounts(yestdate, userOrgCodes));
        return result;
    }

    @Override
    public Map<String, Object> groupMchntSelect2List(String q, QueryRequest request) throws RedpException {

        UpmpUserInfoVO user = CommonUtils.getCurrentUser(upmpSysParamService);
        /* 界面请求参数格式 ： 集团商商户号或名称 & 法人行行号  */
        if (null == q) {
            return null;
        }
        q = q.replaceAll("&amp;", "&");

        String code = "";
        String name = "";
        String[] param = q.split("&");
        if (Common.isNotBlank(param) && param.length > 0) {
            code = param[0];
            name = param[0];
        }
        String instId = "";
        if (Common.isNotBlank(param) && param.length > 1) {
            if (Common.isNotBlank(param[1])) {
                instId = param[1];
            }
        }
        if (user.isAdmin() && Common.isBlank(instId)) {
            log.info("集团商户列表查询参数[instId]为空，无法检索数据");
            return null;
        } else if (!user.isAdmin() && Common.isBlank(instId)) {
            instId = user.getInstId();
        }

        GroupMchntListQueryRequest req = new GroupMchntListQueryRequest();
        int pageIndex = Common.isBlank(request.getPageNum()) ? 1 : request.getPageNum();
        int pageSize = Common.isBlank(request.getPageSize()) ? Integer.parseInt(BusinessContainer.ECP_PAGE_MAXROWS) : request.getPageSize();
        String traceNo = genMerOrder(instId);

        req.setPageIndex(pageIndex - 1);//联机页码从0开始，select2页码从1开始
        req.setPageSize(pageSize);
        req.setGroupMchntNo(code);
        req.setGroupMchntName(name);
        req.setUserId(user.getId());
        GroupMchntListQueryResponse resp = groupMchntListQuery(instId, user, req, bompMchntQueryService, traceNo);

        Map<String, Object> maps = new HashMap<String, Object>();
        if (Common.isNotBlank(resp)) {
            List<GroupMchntInfoBean> list = Lists.newArrayList();
            if (Common.isNotBlank(resp) && CollectionUtils.isNotEmpty(resp.getGroupMchntInfoList())) {
                list = resp.getGroupMchntInfoList();
            }

            if (CollectionUtils.isNotEmpty(list)) {
                Map<String, String> map = new HashMap<String, String>();
                List<Object> rst = new ArrayList<Object>();
                for (GroupMchntInfoBean groupMchnt : list) {

                    map = new HashMap<String, String>();
                    map.put("grpNo", groupMchnt.getGroupMchntNo());
                    map.put("grpDesc", groupMchnt.getGroupMchntName());
                    rst.add(map);
                }
                maps.put("results", rst);
                maps.put("total", resp.getTotalRows());
                if (Integer.valueOf(pageIndex) * Integer.valueOf(pageSize) > resp.getTotalRows()) {
                    maps.put("more", false);
                } else {
                    maps.put("more", true);
                }
            }
        }
        return maps;
    }

    /**
     * 人行行名行号模糊查询
     *
     * @param instId
     * @param user
     * @param req
     * @param bompQueryService
     * @param traceNo
     * @return
     */
    public ManagerInfoListQueryResponse bankNameCodeQuery(String instId, UpmpUserInfoVO user, ManagerInfoListQueryRequest req, BompPublicQueryService bompQueryService, String traceNo) throws RedpException {

        req.setHeader(CommonUtils.packageBompHeader(traceNo, BompTxnNumEnum.managerInfoListQuery.getType(), instId, null));
        req.setUserId(user.getId());

        try {
            log.info("法人行[" + user.getInstId() + "],用户标识[" + req.getUserId() + "]" + BompTxnNumEnum.managerInfoListQuery.getDesc() + "交易请求报文：" + JSON.toJSONString(req));

            Result<ManagerInfoListQueryResponse> response = bompQueryService.managerInfoListQuery(req);
            log.info("法人行[" + user.getInstId() + "],用户标识[" + req.getUserId() + "]" + BompTxnNumEnum.managerInfoListQuery.getDesc() + "交易返回报文：" + JSON.toJSONString(response));
            if (response.isSuccess()) {
                ManagerInfoListQueryResponse resp = response.getResult();
                // 返回码：00000000-进件成功，其他均视为失败
                if (BusinessContainer.BSPS_SUCCESS.equals(resp.getRespCode())) {
                    log.info("法人行[" + user.getInstId() + "],用户标识[" + req.getUserId() + "]" + BompTxnNumEnum.managerInfoListQuery.getDesc() + "交易成功");
                    return resp;
                } else {
                    log.error("法人行[" + user.getInstId() + "],用户标识[" + req.getUserId() + "]" + BompTxnNumEnum.managerInfoListQuery.getDesc() + "交易失败");
                    return null;
                }
            } else {
                log.error("法人行[" + user.getInstId() + "],用户标识[" + req.getUserId() + "]" + BompTxnNumEnum.managerInfoListQuery.getDesc() + "交易没有获得返回信息");
                return null;
            }
        } catch (Exception e) {
            // TODO: handle exception
            log.error("法人行[" + user.getInstId() + "],用户标识[" + req.getUserId() + "]" + BompTxnNumEnum.managerInfoListQuery.getDesc() + "交易出现异常，异常信息：" + e.getMessage(), e);
            throw new RedpException("法人行[" + user.getInstId() + "],用户标识[" + req.getUserId() + "]" + BompTxnNumEnum.managerInfoListQuery.getDesc() + "交易出现异常，异常信息：" + e.getMessage());
        }
    }

    @Override
    public Map<String, Object> managerInfoSelect2List(String q, QueryRequest request) throws RedpException {
        UpmpUserInfoVO user = CommonUtils.getCurrentUser(upmpSysParamService);
        /* 界面请求参数格式 ： 拓展经理工号或名称 & 法人行行号 & 签约机构号类型 & 签约机构号  */
        if (null == q) {
            return null;
        }
        q = q.replaceAll("&amp;", "&");

        String code = "";
        String name = "";
        String[] param = q.split("&");
        if (Common.isNotBlank(param) && param.length > 0) {
            code = param[0];
            name = param[0];
        }
        String instId = "";
        if (Common.isNotBlank(param) && param.length > 1) {
            if (Common.isNotBlank(param[1])) {
                instId = param[1];
            }
        }
        if (user.isAdmin() && Common.isBlank(instId)) {
            log.info("拓展经理列表查询参数[instId]为空，无法检索数据");
            return null;
        } else if (!user.isAdmin() && Common.isBlank(instId)) {
            instId = user.getInstId();
        }
        String signInstType = "";
        if (Common.isNotBlank(param) && param.length > 2) {
            if (Common.isNotBlank(param[2])) {
                signInstType = param[2];
            }
            if (Common.isBlank(signInstType)) {
                signInstType = BusinessContainer.MANAGER_SIGN_INST_BANK;
            }
        }
        String orgCode = "";
        if (Common.isNotBlank(param) && param.length > 3) {
            if (Common.isNotBlank(param[3])) {
                orgCode = param[3];
            }
        }
        String roleType = "";
        if (Common.isNotBlank(param) && param.length > 4) {
            if (Common.isNotBlank(param[4])) {
                roleType = param[4];
            }
        }
        if (Common.isBlank(orgCode)) {
            UpmpOrganization org = organizationService.getOrgByUser(user, instId);
            if (Common.isBlank(org)) {
                log.info("拓展经理列表查询获取签约机构号参数为空，无法检索数据");
                return null;
            }
            orgCode = org.getOrgCode();
        }
        ManagerInfoListQueryRequest req = new ManagerInfoListQueryRequest();
        int pageIndex = Common.isBlank(request.getPageNum()) ? 1 : request.getPageNum();
        int pageSize = Common.isBlank(request.getPageSize()) ? Integer.parseInt(BusinessContainer.ECP_PAGE_MAXROWS) : request.getPageSize();
        String traceNo = genMerOrder(instId);

        req.setPageIndex(pageIndex - 1);//联机页码从0开始，select2页码从1开始
        req.setPageSize(pageSize);
        req.setMangerId(code);
        req.setMangerName(name);
        req.setUserId(user.getId());
        req.setSignInstType(signInstType);
        req.setSignInstId(orgCode);
        req.setRoleType(roleType);
        ManagerInfoListQueryResponse resp = bankNameCodeQuery(instId, user, req, bompPublicQueryService, traceNo);


        Map<String, Object> maps = new HashMap<String, Object>();
        if (Common.isNotBlank(resp)) {
            List<ManagerInfoBean> list = Lists.newArrayList();
            if (Common.isNotBlank(resp) && CollectionUtils.isNotEmpty(resp.getManagerInfoList())) {
                list = resp.getManagerInfoList();
            }

            if (CollectionUtils.isNotEmpty(list)) {
                Map<String, String> map = new HashMap<String, String>();
                List<Object> rst = new ArrayList<Object>();
                for (ManagerInfoBean mchnt : list) {

                    map = new HashMap<String, String>();
                    map.put("id", mchnt.getManagerId());
                    map.put("name", mchnt.getManagerName());
                    map.put("managerPhone", mchnt.getManagerPhone());
                    // map.put("belorgname",mc.getBelOrgName());
                    rst.add(map);
                }
                maps.put("results", rst);
                maps.put("total", resp.getTotalRows());
                if (Integer.valueOf(pageIndex) * Integer.valueOf(pageSize) > resp.getTotalRows()) {
                    maps.put("more", false);
                } else {
                    maps.put("more", true);
                }
            }
        }
        return maps;
    }

    @Override
    public Page<ManagerInfoBean> managerInfoList(QueryRequest request, String instId, String managerName, String roleType, String signInstType, String orgCode) {
        UpmpUserInfoVO user = CommonUtils.getCurrentUser(upmpSysParamService);

        /* 拓展经理工号或名称 & 法人行行号 & 签约机构号类型 & 签约机构号  */
        String code = "";//暂时为空
        String name = managerName;
        if (user.isAdmin() && Common.isBlank(instId)) {
            log.info("拓展经理列表查询参数[instId]为空，无法检索数据");
            return null;
        } else if (!user.isAdmin() && Common.isBlank(instId)) {
            instId = user.getInstId();
        }
        if (Common.isBlank(signInstType)) {
            signInstType = BusinessContainer.MANAGER_SIGN_INST_BANK;
        }
        //不传拓展机构，默认不显示数据
        if (Common.isBlank(orgCode)) {
//            UpmpOrganization org = organizationService.getOrgByUser(user,instId);
//            if(Common.isBlank(org)){
//                log.info("拓展经理列表查询获取签约机构号参数为空，无法检索数据");
//                return null;
//            }
            orgCode = "--";
        }
        Page<ManagerInfoBean> page = new Page<>();
        SortUtil.handlePageSort(request, page, true);
        int pageIndex = Common.isBlank(request.getPageNum()) ? 1 : request.getPageNum();
        int pageSize = Common.isBlank(request.getPageSize()) ? Integer.parseInt(BusinessContainer.ECP_PAGE_MAXROWS) : request.getPageSize();
        String traceNo = genMerOrder(instId);
        try {
            ManagerInfoListQueryRequest req = new ManagerInfoListQueryRequest();
            req.setPageIndex(pageIndex);
            req.setPageSize(pageSize);
            req.setMangerId(code);
            req.setMangerName(name);
            req.setUserId(user.getId());
            req.setSignInstType(signInstType);
            req.setSignInstId(orgCode);
            if (Common.isNotBlank(roleType)) {
                req.setRoleType(roleType);
            }
            ManagerInfoListQueryResponse resp = bankNameCodeQuery(instId, user, req, bompPublicQueryService, traceNo);
            List<ManagerInfoBean> list = Lists.newArrayList();
            if (Common.isNotBlank(resp) && CollectionUtils.isNotEmpty(resp.getManagerInfoList())) {
                list = resp.getManagerInfoList();
                page.setRecords(list);
                page.setTotal(resp.getTotalRows());
            } else {
                page.setRecords(list);
                page.setTotal(0);
            }

            return page;
        } catch (Exception e) {
            log.error("查询拓展经理信息列表出现异常", e);
            return page;
        }

    }

    @Override
    public Map<String, Object> bankNameCodeQuerySelect2List(String q, QueryRequest request) throws RedpException {
        UpmpUserInfoVO user = CommonUtils.getCurrentUser(upmpSysParamService);

        if (null == q) {
            return null;
        }
        q = q.replaceAll("&amp;", "&");

        String code = "";
        String name = "";
        String[] param = q.split("&");
        if (Common.isNotBlank(param) && param.length > 0) {
            code = param[0];
            name = param[0];
        }
        String instId = "";
        if (Common.isNotBlank(param) && param.length > 1) {
            if (Common.isNotBlank(param[1])) {
                instId = param[1];
            }
        }
        if (user.isAdmin() && Common.isBlank(instId)) {
            log.info("人行行名行号模糊查询[instId]为空，无法检索数据");
            return null;
        } else if (!user.isAdmin() && Common.isBlank(instId)) {
            instId = user.getInstId();
        }

        BankNameCodeQueryRequest req = new BankNameCodeQueryRequest();
        int pageIndex = Common.isBlank(request.getPageNum()) ? 1 : request.getPageNum();
        int pageSize = Common.isBlank(request.getPageSize()) ? Integer.parseInt(BusinessContainer.ECP_PAGE_MAXROWS) : request.getPageSize();
        String traceNo = genMerOrder(instId);
        req.setPageIndex(pageIndex - 1);//联机页码从0开始，select2页码从1开始
        req.setPageSize(pageSize);
        req.setBankCode(code);
        req.setBankName(name);
        req.setUserId(user.getId());

        BankNameCodeQueryResponse resp = managerInfoListQuery(instId, user, req, bompPublicQueryService, traceNo);


        Map<String, Object> maps = new HashMap<String, Object>();
        if (Common.isNotBlank(resp)) {
            List<BankNameCodeInfoBean> list = Lists.newArrayList();
            if (Common.isNotBlank(resp) && CollectionUtils.isNotEmpty(resp.getBankNameCodeInfoBeanList())) {
                list = resp.getBankNameCodeInfoBeanList();
            }

            if (CollectionUtils.isNotEmpty(list)) {
                Map<String, String> map = new HashMap<String, String>();
                List<Object> rst = new ArrayList<Object>();
                for (BankNameCodeInfoBean bank : list) {

                    map = new HashMap<String, String>();
                    map.put("id", bank.getBankBranchCode());
                    map.put("name", bank.getBankBranchName());
                    rst.add(map);
                }
                maps.put("results", rst);
                maps.put("total", resp.getTotalRows());
                if (Integer.valueOf(pageIndex) * Integer.valueOf(pageSize) > resp.getTotalRows()) {
                    maps.put("more", false);
                } else {
                    maps.put("more", true);
                }
            }
        }
        return maps;
    }

    /**
     * 拓展经理列表查询
     *
     * @param instId
     * @param user
     * @param req
     * @param bompQueryService
     * @param traceNo
     * @return
     */
    public BankNameCodeQueryResponse managerInfoListQuery(String instId, UpmpUserInfoVO user, BankNameCodeQueryRequest req, BompPublicQueryService bompQueryService, String traceNo) throws RedpException {

        req.setHeader(CommonUtils.packageBompHeader(traceNo, BompTxnNumEnum.bankNameCodeQuery.getType(), instId, null));
        req.setUserId(user.getId());

        try {
            log.info("法人行[" + user.getInstId() + "],用户标识[" + req.getUserId() + "]" + BompTxnNumEnum.bankNameCodeQuery.getDesc() + "交易请求报文：" + JSON.toJSONString(req));

            Result<BankNameCodeQueryResponse> response = bompQueryService.bankNameCodeQuery(req);
            log.info("法人行[" + user.getInstId() + "],用户标识[" + req.getUserId() + "]" + BompTxnNumEnum.bankNameCodeQuery.getDesc() + "交易返回报文：" + JSON.toJSONString(response));
            if (response.isSuccess()) {
                BankNameCodeQueryResponse resp = response.getResult();
                // 返回码：00000000-进件成功，其他均视为失败
                if (BusinessContainer.BSPS_SUCCESS.equals(resp.getRespCode())) {
                    log.info("法人行[" + user.getInstId() + "],用户标识[" + req.getUserId() + "]" + BompTxnNumEnum.bankNameCodeQuery.getDesc() + "交易成功");
                    return resp;
                } else {
                    log.error("法人行[" + user.getInstId() + "],用户标识[" + req.getUserId() + "]" + BompTxnNumEnum.bankNameCodeQuery.getDesc() + "交易失败");
                    return null;
                }
            } else {
                log.error("法人行[" + user.getInstId() + "],用户标识[" + req.getUserId() + "]" + BompTxnNumEnum.bankNameCodeQuery.getDesc() + "交易没有获得返回信息");
                return null;
            }
        } catch (Exception e) {
            // TODO: handle exception
            log.error("法人行[" + user.getInstId() + "],用户标识[" + req.getUserId() + "]" + BompTxnNumEnum.bankNameCodeQuery.getDesc() + "交易出现异常，异常信息：" + e.getMessage(), e);
            throw new RedpException("法人行[" + user.getInstId() + "],用户标识[" + req.getUserId() + "]" + BompTxnNumEnum.bankNameCodeQuery.getDesc() + "交易出现异常，异常信息：" + e.getMessage());
        }
    }

    @Override
    public IPage<UpmpBMchntBaseInfo> mchntFormalSelect2List(String q, QueryRequest request) throws RedpException {
        UpmpUserInfoVO user = CommonUtils.getCurrentUser(upmpSysParamService);
//        String traceNo = genMerOrder(user.getInstId());
        if (null == q) {
            return null;
        }
        q = q.replaceAll("&amp;", "&");

        String mchntNameOrNum = "";
        String[] param = q.split("&");
        if (null != param && param.length > 0) {
            mchntNameOrNum = param[0];
        }
        String instId = "";
        if (null != param && param.length > 1) {
            if (Common.isNotBlank(param[1])) {
                instId = param[1];
            }
        }
        if (StringUtils.isBlank(instId)) {
            instId = user.getInstId();
        }
        try {
            LambdaQueryWrapper<UpmpBMchntBaseInfo> queryWrapper = new LambdaQueryWrapper<>();
            queryWrapper.eq(UpmpBMchntBaseInfo::getMchntStatus, "01");
            queryWrapper.eq(UpmpBMchntBaseInfo::getInstId, instId);
            if (null != user && !user.isAdmin()) {
//                queryWrapper.in(UpmpBMchntBaseInfo::getSignInstId, Arrays.asList(GZIPUtils.uncompressToString(user.getUserOrgCodes()).split(",")));
            }
            if (StringUtils.isNotEmpty(mchntNameOrNum)) {
                String finalMchntNameOrNum = mchntNameOrNum;
                queryWrapper.or(qw -> qw.likeRight(UpmpBMchntBaseInfo::getMchntNo, finalMchntNameOrNum).or().likeRight(UpmpBMchntBaseInfo::getMchntName, finalMchntNameOrNum));
            }
            queryWrapper.orderByDesc(UpmpBMchntBaseInfo::getCreateTime);
            Page<UpmpBMchntBaseInfo> page = new Page<>();
            SortUtil.handlePageSort(request, page, true);
            return this.page(page, queryWrapper);
        } catch (Exception e) {
            log.error("获取商户信息失败", e);
            return null;
        }
    }

    @Override
    public Map<String, Object> feeTemplateSelect2List(String q, QueryRequest request) throws RedpException {
        UpmpUserInfoVO user = CommonUtils.getCurrentUser(upmpSysParamService);

        q = q.replaceAll("&amp;", "&");

        String code = "";
        String name = "";
        String[] param = q.split("&");
        if (Common.isNotBlank(param) && param.length > 0) {
            code = param[0];
            name = param[0];
        }
        String instId = "";
        if (Common.isNotBlank(param) && param.length > 1) {
            if (Common.isNotBlank(param[1])) {
                instId = param[1];
            }
        }
        FeeTemplateListQueryRequest req = new FeeTemplateListQueryRequest();
        int pageIndex = Common.isBlank(request.getPageNum()) ? 1 : request.getPageNum();
        int pageSize = Common.isBlank(request.getPageSize()) ? Integer.parseInt(BusinessContainer.ECP_PAGE_MAXROWS) : request.getPageSize();
        String traceNo = genMerOrder(instId);
        req.setFeeTemplateCode(code);
        req.setFeeTemplateName(name);
        req.setPageIndex(pageIndex - 1);//联机页码从0开始，select2页码从1开始
        req.setPageSize(pageSize);
        req.setUserId(user.getId());
        FeeTemplateListQueryResponse resp = feeTemplateListQuery(instId, user, req, bompPublicQueryService, traceNo);


        Map<String, Object> maps = new HashMap<String, Object>();
        if (Common.isNotBlank(resp)) {
            List<FeeTemplateInfoBean> list = Lists.newArrayList();
            if (Common.isNotBlank(resp) && CollectionUtils.isNotEmpty(resp.getFeeTemplateInfoList())) {
                list = resp.getFeeTemplateInfoList();
            }

            if (CollectionUtils.isNotEmpty(list)) {
                Map<String, String> map = new HashMap<String, String>();
                List<Object> rst = new ArrayList<Object>();
                for (FeeTemplateInfoBean fee : list) {

                    map = new HashMap<String, String>();
                    map.put("id", fee.getFeeTemplateCode());
                    map.put("name", fee.getFeeTemplateName());
                    // map.put("belorgname",mc.getBelOrgName());
                    rst.add(map);
                }
                maps.put("results", rst);
                maps.put("total", resp.getTotalRows());
                if (Integer.valueOf(pageIndex) * Integer.valueOf(pageSize) > resp.getTotalRows()) {
                    maps.put("more", false);
                } else {
                    maps.put("more", true);
                }
            }
        }
        return maps;
    }

    @Override
    public Map<String, Object> cupsmchntSelect2List(String q, QueryRequest request) throws RedpException {
        UpmpUserInfoVO user = CommonUtils.getCurrentUser(upmpSysParamService);
        String traceNo = genMerOrder(user.getInstId());
        q = q.replaceAll("&amp;", "&");

        String BaseProdCode = "";
        String TxnGroup = "";
        String[] param = q.split("&");
        if (null != param && param.length > 0) {
            BaseProdCode = param[1];
            TxnGroup = param[2];
        }

        ChannelInfoListQueryRequest req = new ChannelInfoListQueryRequest();
        int pageIndex = Common.isBlank(request.getPageNum()) ? 1 : request.getPageNum();
        int pageSize = Common.isBlank(request.getPageSize()) ? Integer.parseInt(BusinessContainer.ECP_PAGE_MAXROWS) : request.getPageSize();
        req.setDstChannelId("UPAC");
        req.setTxnGroup(TxnGroup);
        req.setBaseProdCode(BaseProdCode);

        ChannelInfoListQueryResponse resp = cupsmchntSelect2List(user.getInstId(), user, req, bompPublicQueryService, traceNo);

        Map<String, Object> maps = new HashMap<String, Object>();
        if (Common.isNotBlank(resp)) {
            List<ChannelInfoBean> list = Lists.newArrayList();
            if (Common.isNotBlank(resp) && CollectionUtils.isNotEmpty(resp.getChannelInfoList())) {
                list = resp.getChannelInfoList();
            }

            if (CollectionUtils.isNotEmpty(list)) {
                Map<String, String> map = new HashMap<String, String>();
                List<Object> rst = new ArrayList<Object>();
                for (ChannelInfoBean mchnt : list) {
                    map = new HashMap<String, String>();
                    map.put("id", mchnt.getDstChannelType() + mchnt.getProviderMchntNo() + "-" + mchnt.getDstChannelName());
//                    map.put("name", mchnt.getDstChannelName());
                    rst.add(map);
                }
                maps.put("results", rst);
            }
        }
        return maps;
    }

    public ChannelInfoListQueryResponse cupsmchntSelect2List(String instId, UpmpUserInfoVO user, ChannelInfoListQueryRequest req, BompPublicQueryService bompQueryService, String traceNo) throws RedpException {
        req.setHeader(CommonUtils.packageBompHeader(traceNo, BompTxnNumEnum.channelInfoListQuery.getType(), instId, null));
        req.setUserId(user.getId());
        try {
            log.info("法人行[" + user.getInstId() + "],用户标识[" + req.getUserId() + "]" + BompTxnNumEnum.channelInfoListQuery.getDesc() + "交易请求报文：" + JSON.toJSONString(req));

            Result<ChannelInfoListQueryResponse> response = bompQueryService.channelInfoListQuery(req);
            log.info("法人行[" + user.getInstId() + "],用户标识[" + req.getUserId() + "]" + BompTxnNumEnum.channelInfoListQuery.getDesc() + "交易返回报文：" + JSON.toJSONString(response));
            if (response.isSuccess()) {
                ChannelInfoListQueryResponse resp = response.getResult();
                // 返回码：00000000-进件成功，其他均视为失败
                if (BusinessContainer.BSPS_SUCCESS.equals(resp.getRespCode())) {
                    log.info("法人行[" + user.getInstId() + "],用户标识[" + req.getUserId() + "]" + BompTxnNumEnum.channelInfoListQuery.getDesc() + "交易成功");
                    return resp;
                } else {
                    log.error("法人行[" + user.getInstId() + "],用户标识[" + req.getUserId() + "]" + BompTxnNumEnum.channelInfoListQuery.getDesc() + "交易失败");
                    return null;
                }
            } else {
                log.error("法人行[" + user.getInstId() + "],用户标识[" + req.getUserId() + "]" + BompTxnNumEnum.channelInfoListQuery.getDesc() + "交易没有获得返回信息");
                return null;
            }
        } catch (Exception e) {
            // TODO: handle exception
            log.error("法人行[" + user.getInstId() + "],用户标识[" + req.getUserId() + "]" + BompTxnNumEnum.channelInfoListQuery.getDesc() + "交易出现异常，异常信息：" + e.getMessage(), e);
            throw new RedpException("法人行[" + user.getInstId() + "],用户标识[" + req.getUserId() + "]" + BompTxnNumEnum.channelInfoListQuery.getDesc() + "交易出现异常，异常信息：" + e.getMessage());
        }
    }

    @Override
    public Map<String, Object> registerselect2(String q, QueryRequest request) throws RedpException {
        UpmpUserInfoVO user = CommonUtils.getCurrentUser(upmpSysParamService);

        q = q.replaceAll("&amp;", "&");
        RegionInfoQueryRequest req = new RegionInfoQueryRequest();
        String code = "";
        String name = "";
        String[] param = q.split("&");
        if (null != param && param.length > 0) {
            name = param[0];
            req.setRegionName(name);
        }
        String instId = "";
        if (null != param && param.length > 1) {
            if (Common.isNotBlank(param[1])) {
                instId = param[1];
            }
        }
        String regionLevel = "";
        if (null != param && param.length > 2) {
            if (Common.isNotBlank(param[2])) {
                regionLevel = param[2];
            }
        }
        String superRegionCode = "";
        if (null != param && param.length > 3) {
            if (Common.isNotBlank(param[3])) {
                superRegionCode = param[3];
            }
            req.setSuperRegionCode(superRegionCode);
        }
        int pageIndex = Common.isBlank(request.getPageNum()) ? 1 : request.getPageNum();
        int pageSize = Common.isBlank(request.getPageSize()) ? Integer.parseInt(BusinessContainer.ECP_PAGE_MAXROWS) : request.getPageSize();
        String traceNo = genMerOrder(instId);
        req.setPageIndex(pageIndex - 1);//联机页码从0开始，select2页码从1开始
        req.setPageSize(pageSize);
        req.setUserId(user.getId());
        req.setRegionLevel(regionLevel);

        RegionInfoQueryResponse resp = registerListQuery(instId, user, req, bompPublicQueryService, traceNo);

        Map<String, Object> maps = new HashMap<String, Object>();
        if (Common.isNotBlank(resp)) {
            List<RegionInfoBean> list = Lists.newArrayList();
            if (Common.isNotBlank(resp) && CollectionUtils.isNotEmpty(resp.getRegionInfoList())) {
                list = resp.getRegionInfoList();
            }

            List<Object> rst = new ArrayList<Object>();
            if (pageIndex == 1) {
                Map<String, String> map1 = new HashMap<String, String>();
                map1.put("id", "");
                map1.put("name", "请选择...");
                rst.add(map1);
            }

            if (CollectionUtils.isNotEmpty(list)) {
                Map<String, String> map = new HashMap<String, String>();
                for (RegionInfoBean regioninfo : list) {

                    map = new HashMap<String, String>();
                    map.put("id", regioninfo.getRegionCode());
                    map.put("name", regioninfo.getRegionName());
                    rst.add(map);
                }
                maps.put("results", rst);
                maps.put("total", resp.getTotalRows());
                if (Integer.valueOf(pageIndex) * Integer.valueOf(pageSize) > resp.getTotalRows()) {
                    maps.put("more", false);
                } else {
                    maps.put("more", true);
                }
            }
        }
        return maps;
    }

    @Override
    public IPage<UpmpBMchntBaseInfo> chainMchntNoSelect2List(QueryRequest request, String q) {
        if (null == q) {
            return null;
        }
        q = q.replaceAll("&amp;", "&");
        String instId = "";
        String[] param = q.split("&");
        if (null != param && param.length > 0) {
            instId = param[1];
        }
        String signInstId = "";
        if (null != param && param.length > 1) {
            if (Common.isNotBlank(param[1])) {
                signInstId = param[2];
            }
        }
        String mchntNo = "";
        if (null != param && param.length > 0) {
            mchntNo = param[0];
        }

        LambdaQueryWrapper<UpmpBMchntBaseInfo> queryWrapper = new LambdaQueryWrapper<>();
        if (Common.isNotBlank(instId)) {
            queryWrapper.eq(UpmpBMchntBaseInfo::getInstId, instId);
        }
        if (Common.isNotBlank(signInstId)) {
            queryWrapper.eq(UpmpBMchntBaseInfo::getSignInstId, signInstId);
        }
        if (Common.isNotBlank(mchntNo)) {
            String finalMchntNo = mchntNo;
            queryWrapper.or(qw -> qw.likeRight(UpmpBMchntBaseInfo::getMchntNo, finalMchntNo).likeRight(UpmpBMchntBaseInfo::getMchntName, finalMchntNo));
        }
        queryWrapper.eq(UpmpBMchntBaseInfo::getMchntType, MchntTypeEnum.CHAIN_MCHNT.getType());
        queryWrapper.eq(UpmpBMchntBaseInfo::getMchntStatus, BizDataStatusEnum.STATUS_NORMAL.getType());
        queryWrapper.orderByDesc(UpmpBMchntBaseInfo::getMchntNo);
        Page<UpmpBMchntBaseInfo> page = new Page<>();
        SortUtil.handlePageSort(request, page, true);
        return this.page(page, queryWrapper);

    }

    @Override
    public List<UpmpBMchntBaseInfo> getBMchntBaseInfoByMchntLevel(String mchntLevel) {

        LambdaQueryWrapper<UpmpBMchntBaseInfo> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(UpmpBMchntBaseInfo::getMchntLevel, mchntLevel);
        queryWrapper.ne(UpmpBMchntBaseInfo::getMchntStatus, "03");
        return this.list(queryWrapper);
    }

    @Override
    public OperationResult imageFileUpDownload(String instId, ImageFileUpDownloadRequest req, BompMchntManageService bompMchntManageService,
                                               String traceNo, String type) throws RedpException {
        req.setHeader(CommonUtils.packageBompHeader(traceNo, BompTxnNumEnum.imageFileUpDownload.getType(), instId, type));

        Map<String, Object> result = Maps.newHashMap();
        try {
            String imageData = req.getImageData();
            if (req.getOprType().equals("00")) {
                byte[] b = Base64.getDecoder().decode(imageData);
                if (b.length > 5242880) {
                    return OperationResult.buildFailureResult("图片大小超出限制5M", "");
                }
            }
            log.info("法人行[" + instId + "],用户标识[" + req.getUserId() + "]" + BompTxnNumEnum.imageFileUpDownload.getDesc() + "交易请求报文：" + JSON.toJSONString(req));

            Result<ImageFileUpDownloadResponse> response = bompMchntManageService.imageFileUpDownload(req);

            log.info("法人行[" + instId + "],用户标识[" + req.getUserId() + "]" + BompTxnNumEnum.imageFileUpDownload.getDesc() + "交易返回报文：" + JSON.toJSONString(response));
            if (response.isSuccess()) {
                ImageFileUpDownloadResponse resp = response.getResult();
                // 返回码：00000000-进件成功，其他均视为失败
                if (BusinessContainer.BSPS_SUCCESS.equals(resp.getRespCode())) {

                    if ("00".equals(req.getOprType()) || "02".equals(req.getOprType()) || "03".equals(req.getOprType())) {
                        String path = new String(Base64.getDecoder().decode(resp.getImageLocalPath()));

                        String fileSuffix = path.substring(path.lastIndexOf(".") + 1);
                        resp.setImageData("data:image/" + fileSuffix + ";base64," + req.getImageData());
                    }

                    log.info("法人行[" + instId + "],用户标识[" + req.getUserId() + "]" + BompTxnNumEnum.imageFileUpDownload.getDesc() + "交易成功");
                    return OperationResult.buildSuccessResult(BompTxnNumEnum.imageFileUpDownload.getDesc() + "交易成功", resp);
                } else {
                    if (resp.getRespDesc().equals("图片不符合限制要求")) {
                        return OperationResult.buildFailureResult("上传文件格式必须为" + BusinessContainer.WHITE_FILE_SUFFIX + "等，请重新提交", resp);
                    } else {
                        return OperationResult.buildFailureResult(BompTxnNumEnum.imageFileUpDownload.getDesc() + "交易失败", resp);
                    }
                }
            } else {
                result.put("resCode", BusinessContainer.ERROR);
                result.put("resMsg", BompTxnNumEnum.imageFileUpDownload.getDesc() + "没有获得返回报文");
                log.error("法人行[" + instId + "],用户标识[" + req.getUserId() + "]" + BompTxnNumEnum.imageFileUpDownload.getDesc() + "交易没有获得返回信息");
                return OperationResult.buildFailureResult(BompTxnNumEnum.imageFileUpDownload.getDesc() + "交易失败", result);
            }
        } catch (Exception e) {
            // TODO: handle exception
            result.put("resCode", BusinessContainer.ERROR);
            result.put("resMsg", e.getMessage());
            log.error("法人行[" + instId + "],用户标识[" + req.getUserId() + "]" + BompTxnNumEnum.imageFileUpDownload.getDesc() + "交易出现异常，异常信息：" + e.getMessage(), e);
            return OperationResult.buildFailureResult(BompTxnNumEnum.imageFileUpDownload.getDesc() + "交易失败", result);
        }
    }

    /**
     * 解析excel
     *
     * @param sheet1
     * @param sheet2
     * @param sheet3
     * @param maxRecords
     * @param dbCharsetEnum
     * @return
     */
    @Override
    public StringBuffer analysisExcel(Sheet sheet1, Sheet sheet2, Sheet sheet3, int maxRecords, DBCharsetEnum dbCharsetEnum, List<ImportMchntInfoBean> mchntList) throws RedpException, RedpException {
        int realRows = CommonUtils.findRealRows(sheet1);
        if (maxRecords < realRows) {
            log.error("导入文件中商户基本信息记录数超过{}！", maxRecords);
            throw new RedpException("导入文件中商户基本信息记录数超过" + maxRecords + "！");
        }
        int realRows2 = CommonUtils.findRealRows(sheet2);
        if (realRows != realRows2) {
            log.error("导入文件中商户基本信息记录数与商户签约信息记录数不一致！");
            throw new RedpException("导入文件中商户基本信息记录数与商户签约信息记录数不一致！");
        }
        int realRows3 = CommonUtils.findRealRows(sheet2);
        if (realRows != realRows3) {
            log.error("导入文件中商户基本信息记录数与商户结算信息记录数不一致！");
            throw new RedpException("导入文件中商户基本信息记录数与商户结算信息记录数不一致！");
        }

        StringBuffer bufferAll = new StringBuffer();
        //遍历工作表 行数据
        for (int rowNum = 1; rowNum <= realRows; rowNum++) {
            Row rowSheet1 = sheet1.getRow(rowNum);    //商户基本信息表，第rowNum行数据
            Row rowSheet2 = sheet2.getRow(rowNum);    //商户签约信息表，第rowNum行数据
            Row rowSheet3 = sheet3.getRow(rowNum);    //商户签约信息表，第rowNum行数据
            ImportMchntInfoBean mchntInfo = new ImportMchntInfoBean();
            List<SettleAcctInfoBean> settleAcctInfoList = Lists.newArrayList();
//                    if( row1 == null || row2 == null ) return "s3";
            StringBuffer buffer = new StringBuffer();
            /*  批到时只支持新增不支持修改，不需要送商户号
            String cell0RowSheet1 = CommonUtils.getValue(rowSheet1.getCell(0));	//商户基本信息表，第rowNum行，第一列数据
            String cell0RowSheet2 = CommonUtils.getValue(rowSheet2.getCell(0));	//商户签约信息表，第rowNum行，第一列数据
            String cell0RowSheet3 = CommonUtils.getValue(rowSheet3.getCell(0));	//商户结算信息表，第rowNum行，第一列数据

            if(Common.isNotBlank(cell0RowSheet1) &&!cell0RowSheet1.equals(cell0RowSheet2)){
                log.error("导入文件中商户基本信息sheet页第{}行第1列与商户签约信息第{}行第1列值不一致！",rowNum,rowNum);
                buffer.append("导入文件中商户基本信息sheet页第"+rowNum+1+"行第1列与商户签约信息第"+rowNum+1+"行第1列值不一致！");
                buffer.append("\\r\\n");
                continue;
            }
            if(Common.isNotBlank(cell0RowSheet1) && !cell0RowSheet1.equals(cell0RowSheet3)){
                log.error("导入文件中商户基本信息sheet页第{}行第1列与商户结算信息第{}行第1列值不一致！",rowNum,rowNum);
                buffer.append("导入文件中商户基本信息sheet页第"+rowNum+1+"行第1列与商户结算信息第"+rowNum+1+"行第1列值不一致！");
                buffer.append("\\r\\n");
                continue;
            }
            if(Common.isNotBlank(cell0RowSheet2) && !cell0RowSheet2.equals(cell0RowSheet3)){
                log.error("导入文件中商户签约信息sheet页第{}行第1列与商户结算信息第{}行第1列值不一致！",rowNum,rowNum);
                buffer.append("导入文件中商户签约信息sheet页第"+rowNum+1+"行第1列与商户结算信息第"+rowNum+1+"行第1列值不一致！");
                buffer.append("\\r\\n");
                continue;
            }
            if(Common.isNotBlank(cell0RowSheet1)){//如果商户号不为空则检查商户号是否存在
                BMchntBaseInfo bMchntBaseInfo =new BMchntBaseInfo();//调用接口查询商户基本信息是否存在
                if(Common.isBlank(bMchntBaseInfo)){
                    log.error("导入文件中商户基本信息sheet页第{}行商户号在系统中不存在！",rowNum);
                    buffer.append("导入文件中商户基本信息sheet页第"+rowNum+1+"行商户号在系统中不存在！");
                    buffer.append("\\r\\n");
                    continue;
                }
            }
            */
            MchntBaseInfoBean mchntBaseInfo = new MchntBaseInfoBean();
            /*商户拓展方式默认为03-自主拓展*/
            mchntBaseInfo.setMchntExpandType("03");
            MchntContactsInfoBean mchntContactsInfo = new MchntContactsInfoBean();
            StringBuffer baseErr = new StringBuffer();
            for (int i = 0; i < MchntImportExportInit.mchntImportBaseInfo.size(); i++) {
                ExcelColumnAttr colAttr = MchntImportExportInit.mchntImportBaseInfo.get(i);
                String cellVal = CommonUtils.getValue(rowSheet1.getCell(i));
                if (i == 4 || i == 5) {
                    /*注册地址省、市由中文翻译成数字*/
                    List<RegionInfo> regionInfoLst = regionInfoService.getByName(cellVal);
                    if (null != regionInfoLst && regionInfoLst.size() > 0) {
                        cellVal = regionInfoLst.get(0).getRegionCode();
                    } else {
                        baseErr.append("注册地址错误</br>");
                        continue;
                    }
                } else if (i == 8) {
                    /*经营范围由中文翻译成数字*/
                    List<MerGrpInfo> listMerGrp = merGrpInfoService.findByGrpDesc(cellVal);
                    if (null != listMerGrp && listMerGrp.size() > 0) {
                        cellVal = listMerGrp.get(0).getGrpNo();
                    } else {
                        baseErr.append("经营范围错误</br>");
                        continue;
                    }
                }
                StringBuffer errBuff = CommonUtils.validatSheetCellValue(cellVal, colAttr, rowNum, dbCharsetEnum, "商户基本信息");
                if (Common.isBlank(errBuff)) {

                    if (i >= 0 && i <= 37) {
                        if (cellVal.indexOf("-") >= 0) {
                            cellVal = cellVal.substring(0, cellVal.indexOf("-"));
                        }
                        if (cellVal.indexOf("_") >= 0) {
                            cellVal = cellVal.substring(0, cellVal.indexOf("_"));
                        }
                        CommonUtils.addProperty(colAttr.getColumnEname(), cellVal, mchntBaseInfo);
                    } else {
                        if (cellVal.indexOf("-") >= 0) {
                            cellVal = cellVal.substring(0, cellVal.indexOf("-"));
                        }
                        if (cellVal.indexOf("_") >= 0) {
                            cellVal = cellVal.substring(0, cellVal.indexOf("_"));
                        }
                        CommonUtils.addProperty(colAttr.getColumnEname(), cellVal, mchntContactsInfo);
                    }
                } else {
                    baseErr.append(errBuff);
                    //           baseErr.append("\\r\\n");
                    //             break; //此处注释后对整行数据每个字段完成校验；不注释时，该行数据某个字段校验失败后则不继续校验后面的字段
                }
            }
            if (Common.isNotBlank(baseErr)) {//商户基本信息中此记录有异常
                buffer.append(baseErr);
            }//else {//商户基本信息中此记录没有异常时再校验签约信息

            //先将 mchntBaseInfo、mchntContactsInfo set 到 mchntInfo 里
            mchntInfo.setMchntBaseInfo(mchntBaseInfo);
            mchntInfo.setMchntContactsInfo(mchntContactsInfo);

            //再校验签约信息
            BusinessLicenceInfoBean businessLicenceInfo = new BusinessLicenceInfoBean();
            MchntArtifInfoBean mchntArtifInfo = new MchntArtifInfoBean();
            StringBuffer signErr = new StringBuffer();
            String artifCertType = "";
            for (int i = 0; i < MchntImportExportInit.mchntImportSignInfo.size(); i++) {
                ExcelColumnAttr colAttr = MchntImportExportInit.mchntImportSignInfo.get(i);
                String cellVal = CommonUtils.getValue(rowSheet2.getCell(i));
                if (i == 13) {
                    if ("01".equals(artifCertType)) {
                        /*法人证件类型为身份证时，法人证件号码校验规则改为身份证校验*/
                        colAttr.setValidatMethodEnum(ValidatMethodEnum.CHECK_IDENTITY_NUM);
                    } else {
                        colAttr.setValidatMethodEnum(ValidatMethodEnum.CHECK_ALPH_OR_NUM);
                    }
                }
                if (i == 6 || i == 7) {
                    /*注册地址省、市由中文翻译成数字*/
                    List<RegionInfo> regionInfoLst = regionInfoService.getByName(cellVal);
                    if (null != regionInfoLst && regionInfoLst.size() > 0) {
                        cellVal = regionInfoLst.get(0).getRegionCode();
                    } else {
                        signErr.append("注册地址错误</br>");
                        continue;
                    }
                }
                StringBuffer errBuff = CommonUtils.validatSheetCellValue(cellVal, colAttr, rowNum, dbCharsetEnum, "商户签约信息");
                if (Common.isBlank(errBuff)) {
                    if (i >= 0 && i < 11) {
                        if (cellVal.indexOf("-") >= 0) {
                            cellVal = cellVal.substring(0, cellVal.indexOf("-"));
                        }
                        if (cellVal.indexOf("-") >= 0) {
                            cellVal = cellVal.substring(0, cellVal.indexOf("-"));
                        }
                        if (cellVal.indexOf("_") >= 0) {
                            cellVal = cellVal.substring(0, cellVal.indexOf("_"));
                        }
                        CommonUtils.addProperty(colAttr.getColumnEname(), cellVal, businessLicenceInfo);
                    } else if (i >= 11) {
                        if (cellVal.indexOf("-") >= 0) {
                            cellVal = cellVal.substring(0, cellVal.indexOf("-"));
                        }
                        if (cellVal.indexOf("-") >= 0) {
                            cellVal = cellVal.substring(0, cellVal.indexOf("-"));
                        }
                        if (cellVal.indexOf("_") >= 0) {
                            cellVal = cellVal.substring(0, cellVal.indexOf("_"));
                        }
                        if (i == 12) {
                            artifCertType = cellVal;
                        }
                        CommonUtils.addProperty(colAttr.getColumnEname(), cellVal, mchntArtifInfo);
                    }
                } else {
                    signErr.append(errBuff);
                    //           signErr.append("\\r\\n");
                    //           break;//此处注释后对整行数据每个字段完成校验；不注释时，该行数据某个字段校验失败后则不继续校验后面的字段
                }
            }
            if (Common.isNotBlank(signErr)) {//商户基本信息中此记录有异常
                buffer.append(signErr);
            }//else {//商户签约信息中此记录没有异常时再校验结算信息

            //根据商户基本信息的 商户类型 + 企业性质 设置企业注册类型的值
                    /*企业注册类型
                    01-企业
                    02-个体
                    03-分支机构
                    04-非企业法人
                    */
            if ("071".equals(mchntBaseInfo.getMchntNature())) {
                businessLicenceInfo.setEnterRegisterType("02");
            } else if ("310".equals(mchntBaseInfo.getMchntNature())
                    || "320".equals(mchntBaseInfo.getMchntNature())
                    || "080".equals(mchntBaseInfo.getMchntNature())) {
                businessLicenceInfo.setEnterRegisterType("04");
            } else {
                businessLicenceInfo.setEnterRegisterType("01");
            }

            //先将businessLicenceInfo、mchntArtifInfo set到mchntInfo里
            mchntInfo.setBusinessLicenceInfo(businessLicenceInfo);
            mchntInfo.setMchntArtifInfo(mchntArtifInfo);
            //再校验结算信息
            SettleAcctInfoBean settleAcctInfo = new SettleAcctInfoBean();
            StringBuffer settleErr = new StringBuffer();
            for (int i = 0; i < MchntImportExportInit.mchntImportSettlInfo.size(); i++) {
                ExcelColumnAttr colAttr = MchntImportExportInit.mchntImportSettlInfo.get(i);
                String cellVal = CommonUtils.getValue(rowSheet3.getCell(i));
                if (i == 9 || i == 10) {
                    /*注册地址省、市由中文翻译成数字*/
                    List<RegionInfo> regionInfoLst = regionInfoService.getByName(cellVal);
                    if (null != regionInfoLst && regionInfoLst.size() > 0) {
                        cellVal = regionInfoLst.get(0).getRegionCode();
                    } else {
                        settleErr.append("注册地址错误</br>");
                        continue;
                    }
                }
                StringBuffer errBuff = CommonUtils.validatSheetCellValue(cellVal, colAttr, rowNum, dbCharsetEnum, "商户结算信息");
                if (Common.isBlank(errBuff)) {
                    if (cellVal.indexOf("-") >= 0) {
                        cellVal = cellVal.substring(0, cellVal.indexOf("-"));
                    }
                    if (cellVal.indexOf("_") >= 0) {
                        cellVal = cellVal.substring(0, cellVal.indexOf("_"));
                    }
                    CommonUtils.addProperty(colAttr.getColumnEname(), cellVal, settleAcctInfo);
                } else {
                    settleErr.append(errBuff);
                    //         settleErr.append("\\r\\n");
                    //         break;//此处注释后对整行数据每个字段完成校验；不注释时，该行数据某个字段校验失败后则不继续校验后面的字段
                }
            }
            if (Common.isNotBlank(settleErr)) {
                buffer.append(settleErr);
            } else {
                //将 settleAcctInfo set到  mchntInfo里
                settleAcctInfoList.add(settleAcctInfo);
                mchntInfo.setSettleAcctInfoList(settleAcctInfoList);
            }
            //         }
            //      }
            if (Common.isBlank(buffer)) {
                mchntInfo.setRecordSeq(String.valueOf(rowNum));
                mchntList.add(mchntInfo);
            } else {
                bufferAll.append(buffer);
            }
        }
        return bufferAll;
    }

    @Override
    public OperationResult mchntBatchImport(String instId, MchntBatchImportRequest req,
                                            String traceNo) throws RedpException {
        req.setHeader(CommonUtils.packageBompHeader(traceNo, BompTxnNumEnum.mchntBatchImport.getType(), instId, null));
        UpmpUserInfoVO user = CommonUtils.getCurrentUser(upmpSysParamService);
        UpmpPrivilegeCheck privilegeCheck = upmpPrivilegeCheckService.getPrivilegeCheckByPrivilegeCode(instId,
                oprMenuName + BusinessContainer.AUTH_PRIVILEGE_CODE_SPLIT + PageOptFlagEnum.OPT_FLAG_ADD.getDesc());
        if (null != privilegeCheck && BusinessContainer.YES.equals(privilegeCheck.getChecked())) {
            req.setChecked(BompAuditFlagEnum.CHECK.getType());
            req.setOprMenuId(oprMenuId);
            req.setOprMenuName(oprMenuName);
            req.setWebNextUrl(webNextUrl);
            //设置主记录是否需要显示

        } else {
            req.setChecked(BompAuditFlagEnum.NO_CHECK.getType());
        }


        Map<String, Object> result = Maps.newHashMap();
        try {

            log.info("法人行[" + instId + "],用户标识[" + req.getUserId() + "]" + BompTxnNumEnum.mchntBatchImport.getDesc() + "交易请求报文：" + JSON.toJSONString(req));

            Result<MchntBatchImportResponse> response = bompMchntPublicDealService.mchntBatchImport(req);

            log.info("法人行[" + instId + "],用户标识[" + req.getUserId() + "]" + BompTxnNumEnum.mchntBatchImport.getDesc() + "交易返回报文：" + JSON.toJSONString(response));
            if (response.isSuccess()) {
                MchntBatchImportResponse resp = response.getResult();
                // 返回码：00000000-进件成功，其他均视为失败
                if (BusinessContainer.BSPS_SUCCESS.equals(resp.getRespCode())) {
                    result.put("respCode", resp.getRespCode());
                    result.put("respMsg", resp.getRespDesc());
                    log.error("法人行[" + instId + "],用户标识[" + req.getUserId() + "]" + BompTxnNumEnum.mchntBatchImport.getDesc() + "交易成功");
                    return OperationResult.buildSuccessResult(BompTxnNumEnum.mchntBatchImport.getDesc() + "交易成功", result);
                } else {
                    result.put("respCode", resp.getRespCode());
                    result.put("respMsg", resp.getRespDesc());
                    return OperationResult.buildFailureResult(BompTxnNumEnum.mchntBatchImport.getDesc() + "交易失败", result);
                }
            } else {
                result.put("resCode", BusinessContainer.ERROR);
                result.put("resMsg", BompTxnNumEnum.mchntBatchImport.getDesc() + "没有获得返回报文");
                log.error("法人行[" + instId + "],用户标识[" + req.getUserId() + "]" + BompTxnNumEnum.mchntBatchImport.getDesc() + "交易没有获得返回信息");
                return OperationResult.buildFailureResult(BompTxnNumEnum.mchntBatchImport.getDesc() + "交易失败", result);
            }
        } catch (Exception e) {
            // TODO: handle exception
            result.put("resCode", BusinessContainer.ERROR);
            result.put("resMsg", e.getMessage());
            log.error("法人行[" + instId + "],用户标识[" + req.getUserId() + "]" + BompTxnNumEnum.mchntBatchImport.getDesc() + "交易出现异常，异常信息：" + e.getMessage(), e);
//            throw new RedpException("商户编号为：[" + req.getMchntNo() + "]的商户，"+BompTxnNumEnum.mchntProdInfoManage.getDesc()+"交易出现异常",e);
            return OperationResult.buildFailureResult(BompTxnNumEnum.mchntBatchImport.getDesc() + "交易失败", result);
        }
    }

    @Override
    public HashMap<String, Object> exportFromBomp(HttpServletRequest request, String instId, UpmpUserInfoVO user, String traceNo, int pageIndex, int pageSize) {
        List<ExportMchntInfoBean> resultData = new ArrayList<ExportMchntInfoBean>();
        HashMap<String, Object> resultMap = new HashMap();

        String mchntNo = request.getParameter("mchntNo");
        String signInstId = request.getParameter("signInstId");
        String agentMchntNo = request.getParameter("agentMchntNo");
        String mchntStatus = request.getParameter("mchntStatus");
        String mchntLevel = request.getParameter("mchntLevel");
        String mchntArea = request.getParameter("mchntArea");
        String mchntName = request.getParameter("mchntName");
        String platMchntNo = request.getParameter("platMchntNo");
        try {

            MchntBatchExportRequest req = new MchntBatchExportRequest();
            req.setMchntStatus(mchntStatus);
            req.setMchntNo(mchntNo);
            req.setAgentMchntNo(agentMchntNo);
            req.setMchntLevel(mchntLevel);
            req.setMchntName(mchntName);
            req.setSignInstId(signInstId);
            req.setMchntArea(mchntArea);
            req.setPlatMchntNo(platMchntNo);
            req.setPageSize(pageSize);
            req.setPageIndex(pageIndex);

            MchntBatchExportResponse resp = mchntInfoListExport(instId, user, req, traceNo);
            if (Common.isNotBlank(resp) && CollectionUtils.isNotEmpty(resp.getMchntInfoList())) {
                resultData = resp.getMchntInfoList();
                /*导出第一页之后获取总页数，之后循环导出剩余数据*/
                int totalPage = resp.getTotalPage();
                resultMap.put("totalPage", totalPage);
                resultMap.put("resultData", resultData);
               /* for(pageIndex = 1; pageIndex < totalPage; pageIndex++){
                    req.setPageIndex(pageIndex);
                    resp = mchntInfoListExport(instId,user,req,bompMchntPublicDealService,genMerOrder(user,dataDictService,cbcParamsService));
                    if(Common.isNotBlank(resp) && CollectionUtils.isNotEmpty(resp.getMchntInfoList())){
                        resultData.addAll(resp.getMchntInfoList());
                    }
                }*/
            }
            return resultMap;

        } catch (Exception e) {
            log.error("查询商户信息列表出现异常", e);
            return resultMap;
        }
    }

    @Override
    public List<UpmpBMchntBaseInfo> getByInstId(String instId) {
        return upmpBMchntBaseInfoMapper.findByInstId(instId);
    }

    /**
     * 商户黑名单管理使用此方法  --makeby lizk
     *
     * @param instId
     * @param user
     * @param bompMchntQueryService
     * @param genMerOrder
     * @param mchntNo
     * @param mchntName
     * @param real
     * @return
     */
    @Override
    public MchntBaseInfoQueryResponse mchntBaseInfoQuery(String instId, UpmpUserInfoVO user, BompMchntQueryService bompMchntQueryService, String genMerOrder, String mchntNo, String mchntName, BompQueryTypeEnum real) throws RedpException {
        MchntBaseInfoQueryRequest req = new MchntBaseInfoQueryRequest();
        req.setHeader(CommonUtils.packageBompHeader(genMerOrder, BompTxnNumEnum.mchntBaseInfoQuery.getType(), instId, real.getType()));
        req.setUserId(user.getId());
        req.setMchntNo(mchntNo);
        req.setMchntName(mchntName);

        try {
            log.info("法人行[" + instId + "],用户标识[" + req.getUserId() + "],商户号[" + req.getMchntNo() + "]" + BompTxnNumEnum.mchntBaseInfoQuery.getDesc() + "交易请求报文：" + JSON.toJSONString(req));

            Result<MchntBaseInfoQueryResponse> response = bompMchntQueryService.mchntBaseInfoQuery(req);
            log.info("法人行[" + instId + "],用户标识[" + req.getUserId() + "],商户号[" + req.getMchntNo() + "]" + BompTxnNumEnum.mchntBaseInfoQuery.getDesc() + "交易返回报文：" + JSON.toJSONString(response));
            if (response.isSuccess()) {
                MchntBaseInfoQueryResponse resp = response.getResult();
                // 返回码：00000000-进件成功，其他均视为失败
                if (BusinessContainer.BSPS_SUCCESS.equals(resp.getRespCode())) {
                    log.info("法人行[" + instId + "],用户标识[" + req.getUserId() + "],商户号[" + req.getMchntNo() + "]" + BompTxnNumEnum.mchntBaseInfoQuery.getDesc() + "交易成功");
                    return resp;
                } else {
                    log.error("法人行[" + instId + "],用户标识[" + req.getUserId() + "],商户号[" + req.getMchntNo() + "]" + BompTxnNumEnum.mchntBaseInfoQuery.getDesc() + "交易失败");
                    return null;
                }
            } else {
                log.error("法人行[" + instId + "],用户标识[" + req.getUserId() + "],商户号[" + req.getMchntNo() + "]" + BompTxnNumEnum.mchntBaseInfoQuery.getDesc() + "交易没有获得返回信息");
                return null;
            }
        } catch (Exception e) {
            // TODO: handle exception
            log.error("法人行[" + instId + "],用户标识[" + req.getUserId() + "],商户号[" + req.getMchntNo() + "]" + BompTxnNumEnum.mchntBaseInfoQuery.getDesc() + "交易出现异常，异常信息：" + e.getMessage(), e);
            throw new RedpException("法人行[" + instId + "],用户标识[" + req.getUserId() + "],商户号[" + req.getMchntNo() + "]" + BompTxnNumEnum.mchntBaseInfoQuery.getDesc() + "交易出现异常");
        }
    }

    /**
     * 页面初始化渲染获取分页数据
     *
     * @param request
     * @param entity
     * @return
     */
    @Override
    public IPage<UpmpBMchntBaseInfo> selectByPage(QueryRequest request, UpmpBMchntBaseInfo entity) {
        try {
            //获取当前登录人信息
            UpmpUserInfoVO user = CommonUtils.getCurrentUser(upmpSysParamService);
            List<String> userOrgCodeList = new ArrayList<String>();
            if (StringUtils.isBlank(entity.getInstId())) {
                entity.setInstId(user.getInstId());
            }
            if (null != user && !user.isAdmin()) {
                userOrgCodeList = Arrays.asList(GZIPUtils.uncompressToString(user.getUserOrgCodes()).split(","));
            }
            LambdaQueryWrapper<UpmpBMchntBaseInfo> queryWrapper = new LambdaQueryWrapper<>();
            queryWrapper.eq(UpmpBMchntBaseInfo::getMchntStatus, "01")
                    .and(i -> i.ne(UpmpBMchntBaseInfo::getMchntType, "11")
                            .or(j -> j.eq(UpmpBMchntBaseInfo::getMchntType, "11")
                                    .eq(UpmpBMchntBaseInfo::getIndependentDataFlag, "Y")));

            if (!org.springframework.util.StringUtils.isEmpty(entity.getInstId())) {
                queryWrapper.eq(UpmpBMchntBaseInfo::getInstId, entity.getInstId());
            }
            if (null != user && !user.isAdmin()) {
                queryWrapper.in(UpmpBMchntBaseInfo::getSignInstId, userOrgCodeList);
            }
            if (!org.springframework.util.StringUtils.isEmpty(entity.getSignInstId())) {
                queryWrapper.eq(UpmpBMchntBaseInfo::getSignInstId, entity.getSignInstId());
            }
            if (!org.springframework.util.StringUtils.isEmpty(entity.getMchntNo())) {
                queryWrapper.like(UpmpBMchntBaseInfo::getMchntNo, entity.getMchntNo());
            }
            if (!org.springframework.util.StringUtils.isEmpty(entity.getMchntName())) {
                queryWrapper.like(UpmpBMchntBaseInfo::getMchntName, entity.getMchntName());
            }
            if (!org.springframework.util.StringUtils.isEmpty(entity.getMchntDelayFlag()) && entity.getMchntDelayFlag() != "N") {
                if (entity.getMchntDelayFlag().equals("S")) {
                    entity.setMchntDelayFlag("N");
                }
                queryWrapper.eq(UpmpBMchntBaseInfo::getMchntDelayFlag, entity.getMchntDelayFlag());
            }

            Page<UpmpBMchntBaseInfo> page = new Page<>();
            SortUtil.handlePageSort(request, page, true);
//            Page<UpmpBMchntBaseInfo> baseInfoPage = this.page(page, queryWrapper);
            Page<UpmpBMchntBaseInfo> baseInfoPage = this.page(page, queryWrapper);
            for (UpmpBMchntBaseInfo record : baseInfoPage.getRecords()) {
                String realNetAmt = riskFundInfoService.getRealNetAmt(record.getMchntNo());
                record.setRemark1(realNetAmt);
            }

            return baseInfoPage;
        } catch (Exception e) {
            log.error("获取商户延迟清算管理信息失败", e);
            return null;
        }
    }

    /**
     * 新增延迟清算/解除延迟
     *
     * @param entity
     */
    @Override
    public void editOrRelease(UpmpBMchntBaseInfo entity) throws RedpException {
        String lastUpddt = DateUtils.formatDate(new Date(), "yyyy-MM-dd HH:mm:ss.SSS");
        UpmpBMchntBaseInfo baseInfo = this.baseMapper.selectById(entity.getId());
        if ("upd".equals(entity.getOptFlag())) {
            if (entity.getMchntType().equals("11") && "N".equals(entity.getIndependentDataFlag())) {//判断是否为二级商户
                throw new RedpException("非独立维护商户资料的二级商户不能设置延迟清算");
            }
            //商户号
            UpmpBMchntBaseInfo bymchntno = findByMchntNo(entity.getMchntNo());
            if (Common.isBlank(bymchntno)) {
                throw new RedpException("商户不存在");
            }
            if (bymchntno.getAuditStatus().equals(BizDataAuditStatusEnum.AUDIT_STATUS_ADD_CHECKING) || bymchntno.getAuditStatus().equals(BizDataAuditStatusEnum.AUDIT_STATUS_CANCEL_CHECKING) || bymchntno.getAuditStatus().equals(BizDataAuditStatusEnum.AUDIT_STATUS_STOP_CHECKING) || bymchntno.getAuditStatus().equals(BizDataAuditStatusEnum.AUDIT_STATUS_USE_CHECKING) || bymchntno.getAuditStatus().equals(BizDataAuditStatusEnum.AUDIT_STATUS_UPD_CHECKING)) {
                throw new RedpException("审批流程中商户不可设置延迟清算");
            }
            BeanUtils.copyProperties(entity, baseInfo);
            baseInfo.setMchntDelayFlag("Y");
        } else {//解除延迟
            baseInfo.setMchntDelayFlag("N");
        }
        baseInfo.setLastUpdateTime(lastUpddt);
        this.baseMapper.updateById(baseInfo);
    }

    public MchntBatchExportResponse mchntInfoListExport(String instId, UpmpUserInfoVO user, MchntBatchExportRequest req, String traceNo) throws RedpException {
        req.setHeader(CommonUtils.packageBompHeader(traceNo, BompTxnNumEnum.mchntBatchExport.getType(), instId, null));
        req.setUserId(user.getId());
        try {
            log.info("法人行[" + instId + "],用户标识[" + req.getUserId() + "],商户号[" + req.getMchntNo() + "]" + BompTxnNumEnum.mchntBatchExport.getDesc() + "交易请求报文：" + JSON.toJSONString(req));

            Result<MchntBatchExportResponse> response = bompMchntPublicDealService.mchntBatchExport(req);
            log.info("法人行[" + instId + "],用户标识[" + req.getUserId() + "],商户号[" + req.getMchntNo() + "]" + BompTxnNumEnum.mchntBatchExport.getDesc() + "交易返回报文：" + JSON.toJSONString(response));
            if (response.isSuccess()) {
                MchntBatchExportResponse resp = response.getResult();
                // 返回码：00000000-成功，其他均视为失败
                if (BusinessContainer.BSPS_SUCCESS.equals(resp.getRespCode())) {
                    log.info("法人行[" + instId + "],用户标识[" + req.getUserId() + "],商户号[" + req.getMchntNo() + "]" + BompTxnNumEnum.mchntBatchExport.getDesc() + "交易成功");
                    return resp;
                } else {
                    log.error("法人行[" + instId + "],用户标识[" + req.getUserId() + "],商户号[" + req.getMchntNo() + "]" + BompTxnNumEnum.mchntBatchExport.getDesc() + "交易失败");
                    return null;
                }
            } else {
                log.error("法人行[" + instId + "],用户标识[" + req.getUserId() + "],商户号[" + req.getMchntNo() + "]" + BompTxnNumEnum.mchntBatchExport.getDesc() + "交易没有获得返回信息");
                return null;
            }
        } catch (Exception e) {
            // TODO: handle exception
            log.error("法人行[" + instId + "],用户标识[" + req.getUserId() + "],商户号[" + req.getMchntNo() + "]" + BompTxnNumEnum.mchntBatchExport.getDesc() + "交易出现异常，异常信息：" + e.getMessage(), e);
            throw new RedpException("法人行[" + instId + "],用户标识[" + req.getUserId() + "],商户号[" + req.getMchntNo() + "]" + BompTxnNumEnum.mchntBatchExport.getDesc() + "交易出现异常，异常信息：" + e.getMessage());
        }
    }

    /**
     * 微信实名认证申请
     *
     * @param user
     * @param request
     * @param traceNo
     * @return
     */
    public OperationResult wechatRealNameApply(UpmpUserInfoVO user, HttpServletRequest request, String traceNo) {
        WechatRealNameApplyRequest req = new WechatRealNameApplyRequest();
        String instId = request.getParameter("instId");
        String mchntNo = request.getParameter("mchntNo");
        req.setMchntNo(mchntNo);
        req.setUserId(user.getId());
        req.setHeader(CommonUtils.packageBompHeader(traceNo, BompTxnNumEnum.wechatRealNameApply.getType(), instId, null));
        Map<String, Object> result = Maps.newHashMap();
        try {
            log.info("法人行[" + user.getInstId() + "],用户标识[" + req.getUserId() + "]" + BompTxnNumEnum.wechatRealNameApply.getDesc() + "交易请求报文：" + JSON.toJSONString(req));
            Result<WechatRealNameApplyResponse> response = bompThirdMchntEntryService.wechatRealNameApply(req);
            log.info("法人行[" + user.getInstId() + "],用户标识[" + req.getUserId() + "]" + BompTxnNumEnum.wechatRealNameApply.getDesc() + "交易返回报文：" + JSON.toJSONString(response));
            if (response.isSuccess()) {
                WechatRealNameApplyResponse resp = response.getResult();
                // 返回码：00000000-进件成功，其他均视为失败
                if (BusinessContainer.BSPS_SUCCESS.equals(resp.getRespCode())) {
                    log.info("法人行[" + user.getInstId() + "],用户标识[" + req.getUserId() + "]" + BompTxnNumEnum.wechatRealNameApply.getDesc() + "交易成功");
                    result.put("respCode", resp.getRespCode());
                    result.put("respMsg", resp.getRespDesc());
                    return OperationResult.buildSuccessResult(resp.getRespDesc(), result);
                } else {
                    log.error("法人行[" + user.getInstId() + "],用户标识[" + req.getUserId() + "]" + BompTxnNumEnum.wechatRealNameApply.getDesc() + "交易失败");
                    result.put("respCode", resp.getRespCode());
                    result.put("respMsg", resp.getRespDesc());
                    return OperationResult.buildFailureResult(resp.getRespDesc(), result);
                }
            } else {
                result.put("resCode", BusinessContainer.ERROR);
                result.put("resMsg", BompTxnNumEnum.wechatRealNameApply.getDesc() + "没有获得返回报文");
                log.error(BompTxnNumEnum.wechatRealNameApply.getDesc() + "交易没有获得返回信息");
                return OperationResult.buildFailureResult(response.getResult().getRespDesc(), result);
            }
        } catch (Exception e) {
            // TODO: handle exception
            result.put("resCode", BusinessContainer.ERROR);
            result.put("resMsg", e.getMessage());
            log.error(BompTxnNumEnum.wechatRealNameApply.getDesc() + "交易出现异常，异常信息：" + e.getMessage(), e);
            return OperationResult.buildFailureResult(BompTxnNumEnum.wechatRealNameApply.getDesc() + "失败", result);
        }
    }

    /**
     * 微信实名认证撤销
     *
     * @param user
     * @param request
     * @param traceNo
     * @return
     */
    public OperationResult wechatRealNameApplyCancel(UpmpUserInfoVO user, HttpServletRequest request, String traceNo) {
        WechatRealNameApplyCancelRequest req = new WechatRealNameApplyCancelRequest();
        String instId = request.getParameter("instId");
        String mchntNo = request.getParameter("mchntNo");
        String realNameApplyNo = request.getParameter("realNameApplyNo");
        req.setMchntNo(mchntNo);
        req.setUserId(user.getId());
        req.setRealNameApplyNo(realNameApplyNo);
        req.setHeader(CommonUtils.packageBompHeader(traceNo, BompTxnNumEnum.wechatRealNameApplyCancel.getType(), instId, null));
        Map<String, Object> result = Maps.newHashMap();
        try {
            log.info("法人行[" + user.getInstId() + "],用户标识[" + req.getUserId() + "]" + BompTxnNumEnum.wechatRealNameApplyCancel.getDesc() + "交易请求报文：" + JSON.toJSONString(req));
            Result<WechatRealNameApplyCancelResponse> response = bompThirdMchntEntryService.wechatRealNameApplyCancel(req);
            log.info("法人行[" + user.getInstId() + "],用户标识[" + req.getUserId() + "]" + BompTxnNumEnum.wechatRealNameApplyCancel.getDesc() + "交易返回报文：" + JSON.toJSONString(response));
            if (response.isSuccess()) {
                WechatRealNameApplyCancelResponse resp = response.getResult();
                // 返回码：00000000-进件成功，其他均视为失败
                if (BusinessContainer.BSPS_SUCCESS.equals(resp.getRespCode())) {
                    log.info("法人行[" + user.getInstId() + "],用户标识[" + req.getUserId() + "]" + BompTxnNumEnum.wechatRealNameApplyCancel.getDesc() + "交易成功");
                    result.put("respCode", resp.getRespCode());
                    result.put("respMsg", resp.getRespDesc());
                    return OperationResult.buildSuccessResult(resp.getRespDesc(), result);
                } else {
                    log.error("法人行[" + user.getInstId() + "],用户标识[" + req.getUserId() + "]" + BompTxnNumEnum.wechatRealNameApplyCancel.getDesc() + "交易失败");
                    result.put("respCode", resp.getRespCode());
                    result.put("respMsg", resp.getRespDesc());
                    return OperationResult.buildFailureResult(resp.getRespDesc(), result);
                }
            } else {
                result.put("resCode", BusinessContainer.ERROR);
                result.put("resMsg", BompTxnNumEnum.wechatRealNameApplyCancel.getDesc() + "没有获得返回报文");
                log.error(BompTxnNumEnum.wechatRealNameApplyCancel.getDesc() + "交易没有获得返回信息");
                return OperationResult.buildFailureResult(response.getResult().getRespDesc(), result);
            }
        } catch (Exception e) {
            // TODO: handle exception
            result.put("resCode", BusinessContainer.ERROR);
            result.put("resMsg", e.getMessage());
            log.error(BompTxnNumEnum.wechatRealNameApplyCancel.getDesc() + "交易出现异常，异常信息：" + e.getMessage(), e);
            return OperationResult.buildFailureResult(BompTxnNumEnum.wechatRealNameApplyCancel.getDesc() + "失败", result);
        }
    }


    /**
     * 微信实名认证状态查询
     *
     * @param user
     * @param request
     * @param traceNo
     * @return
     */
    public OperationResult wechatRealNameAuditQuery(UpmpUserInfoVO user, HttpServletRequest request, String traceNo) {
        WechatRealNameAuditQueryRequest req = new WechatRealNameAuditQueryRequest();
        String instId = request.getParameter("instId");
        String mchntNo = request.getParameter("mchntNo");
        String realNameApplyNo = request.getParameter("realNameApplyNo");
        req.setMchntNo(mchntNo);
        req.setUserId(user.getId());
        req.setRealNameApplyNo(realNameApplyNo);
        req.setHeader(CommonUtils.packageBompHeader(traceNo, BompTxnNumEnum.wechatRealNameAuditQuery.getType(), instId, null));
        Map<String, Object> result = Maps.newHashMap();
        try {
            log.info("法人行[" + user.getInstId() + "],用户标识[" + req.getUserId() + "]" + BompTxnNumEnum.wechatRealNameAuditQuery.getDesc() + "交易请求报文：" + JSON.toJSONString(req));
            Result<WechatRealNameAuditQueryResponse> response = bompThirdMchntEntryService.wechatRealNameAuditQuery(req);
            log.info("法人行[" + user.getInstId() + "],用户标识[" + req.getUserId() + "]" + BompTxnNumEnum.wechatRealNameAuditQuery.getDesc() + "交易返回报文：" + JSON.toJSONString(response));
            if (response.isSuccess()) {
                WechatRealNameAuditQueryResponse resp = response.getResult();
                // 返回码：00000000-进件成功，其他均视为失败
                if (BusinessContainer.BSPS_SUCCESS.equals(resp.getRespCode())) {
                    log.info("法人行[" + user.getInstId() + "],用户标识[" + req.getUserId() + "]" + BompTxnNumEnum.wechatRealNameAuditQuery.getDesc() + "交易成功");
                    result.put("respCode", resp.getRespCode());
                    result.put("respMsg", resp.getRespDesc());
                    result.put("realNameApplyStatus", resp.getRealNameApplyStatus());
                    if ("01".equals(resp.getRealNameApplyStatus()) || "02".equals(resp.getRealNameApplyStatus()) || "03".equals(resp.getRealNameApplyStatus()) || "11".equals(resp.getRealNameApplyStatus())) {
                        result.put("qrcodeData", resp.getQrcodeData());
                    }
                    if ("10".equals(resp.getRealNameApplyStatus())) {
                        result.put("applyRejectReason", resp.getApplyRejectReason());
                    }
                    return OperationResult.buildSuccessResult(resp.getRespDesc(), result);
                } else {
                    log.error("法人行[" + user.getInstId() + "],用户标识[" + req.getUserId() + "]" + BompTxnNumEnum.wechatRealNameAuditQuery.getDesc() + "交易失败");
                    result.put("respCode", resp.getRespCode());
                    result.put("respMsg", resp.getRespDesc());
                    return OperationResult.buildFailureResult(resp.getRespDesc(), result);
                }
            } else {
                result.put("resCode", BusinessContainer.ERROR);
                result.put("resMsg", BompTxnNumEnum.wechatRealNameAuditQuery.getDesc() + "没有获得返回报文");
                log.error(BompTxnNumEnum.wechatRealNameAuditQuery.getDesc() + "交易没有获得返回信息");
                return OperationResult.buildFailureResult(response.getResult().getRespDesc(), result);
            }
        } catch (Exception e) {
            // TODO: handle exception
            result.put("resCode", BusinessContainer.ERROR);
            result.put("resMsg", e.getMessage());
            log.error(BompTxnNumEnum.wechatRealNameAuditQuery.getDesc() + "交易出现异常，异常信息：" + e.getMessage(), e);
            return OperationResult.buildFailureResult(BompTxnNumEnum.wechatRealNameAuditQuery.getDesc() + "失败", result);
        }
    }

    @Override
    public List<UpmpBMchntBaseInfo> getMarchantInfoByLevel(String mchntLevel) {
        LambdaQueryWrapper<UpmpBMchntBaseInfo> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(UpmpBMchntBaseInfo::getMchntLevel, mchntLevel);
        return baseMapper.selectList(wrapper);
    }

    /**
     * 业务查询的--交易查询----商户名称查找
     *
     * @param request
     * @return
     */
    @Override
    public Map<String, Object> findMchntBaseInfoListByName(QueryRequest request,UpmpBMchntBaseInfo upmp) {
        UpmpUserInfoVO user = CommonUtils.getCurrentUser(upmpSysParamService);
        String userOrgCodes = user.getOrgCode();
        LambdaQueryWrapper<UpmpBMchntBaseInfo> lambdaQueryWrapper = new LambdaQueryWrapper<>();
/*      q = q.replaceAll("&amp;", "&");
        if (null == q) {
            return null;
        }
        String instId = "";
        String param1 = null;
        String[] param = q.split("&");
        if (null != param && param.length > 0) {
            param1 = param[0];
        }
        if (null != param && param.length > 1) {
            if (Common.isBlank(param[1]) && Common.isNotBlank(user.getInstId())) {
                instId = user.getInstId();
            } else {
                if (user.isAdmin()) {
                    instId = param[1];
                } else {
                    instId = user.getInstId();
                }
            }
        } else {
            instId = user.getInstId();
        }
        if (!StringUtils.isBlank(param1)) {
            lambdaQueryWrapper.likeRight(UpmpBMchntBaseInfo::getMchntName, param1).or().likeRight(UpmpBMchntBaseInfo::getMchntNo, param1);
        }
        */
        if (!Common.isNotBlank(upmp.getInstId())) {
            log.info("没有获取到法人行信息，无法查询机构数据");
            return null;
        }
        if (user.isAdmin()) {
            lambdaQueryWrapper.eq(UpmpBMchntBaseInfo::getInstId, upmp.getInstId());
        } else {
            lambdaQueryWrapper.eq(UpmpBMchntBaseInfo::getSignInstId, userOrgCodes);
        }
        if (!StringUtils.isBlank(upmp.getMchntNo())) {
            lambdaQueryWrapper.likeRight(UpmpBMchntBaseInfo::getMchntName, upmp.getMchntNo()).or().likeRight(UpmpBMchntBaseInfo::getMchntNo, upmp.getMchntNo());
        }
        Page<UpmpBMchntBaseInfo> page = new Page<>();
        SortUtil.handlePageSort(request, page, true);
        Page<UpmpBMchntBaseInfo> page1 = this.page(page, lambdaQueryWrapper);
        List<UpmpBMchntBaseInfo> listx = page1.getRecords();
        Map<String, Object> maps = new HashMap<String, Object>();
        Map<String, String> map = new HashMap<String, String>();
        List<Object> list = new ArrayList<Object>();
        if (listx != null) {
            for (int i = 0; i < listx.size(); i++) {
                UpmpBMchntBaseInfo info = listx.get(i);
                map = new HashMap<String, String>();
                map.put("name", info.getMchntName());
                map.put("id", info.getMchntNo());
                list.add(map);
            }
            maps.put("rows", list);
            maps.put("total", page.getTotal());
            int pageIndex = Common.isBlank(request.getPageNum()) ? 1 : request.getPageNum();
            if (pageIndex == page1.getTotal()) {
                maps.put("more", false);
            } else {
                maps.put("more", true);
            }
        }
        return maps;
    }

    /**
     * 业务查询的--交易查询----二级商户
     *
     * @param request
     * @param q       条件
     * @return
     */
    @Override
    public Map<String, Object> mchntBaseInfoListByNo(QueryRequest request, String q) {
        UpmpUserInfoVO user = CommonUtils.getCurrentUser(upmpSysParamService);
        String userOrgCodes = user.getOrgCode();
        q = q.replaceAll("&amp;", "&");
        LambdaQueryWrapper<UpmpBMchntBaseInfo> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        if (null == q) {
            return null;
        }
        String instId = "";
        String param1 = null;
        String[] param = q.split("&");
        if (null != param && param.length > 0) {
            param1 = param[0];
        }
        if (null != param && param.length > 1) {
            if (Common.isBlank(param[1]) && Common.isNotBlank(user.getInstId())) {
                instId = user.getInstId();
            } else {
                if (user.isAdmin()) {
                    instId = param[1];
                } else {
                    instId = user.getInstId();
                }
            }
        } else {
            instId = user.getInstId();
        }
        String chainMchntNo = "";
        if (null != param && param.length > 2) {
            chainMchntNo = param[2];
        }
        lambdaQueryWrapper.eq(UpmpBMchntBaseInfo::getMchntType, "11").eq(UpmpBMchntBaseInfo::getChainMchntNo, chainMchntNo);
        if (user.isAdmin()) {
            lambdaQueryWrapper.eq(UpmpBMchntBaseInfo::getInstId, instId);
        } else {
            lambdaQueryWrapper.eq(UpmpBMchntBaseInfo::getSignInstId, userOrgCodes);
        }
        if (!StringUtils.isBlank(param1)) {
            lambdaQueryWrapper.likeRight(UpmpBMchntBaseInfo::getMchntName, param1).or().likeRight(UpmpBMchntBaseInfo::getMchntNo, param1);
        }
        Page<UpmpBMchntBaseInfo> page = new Page<>();
        SortUtil.handlePageSort(request, page, true);
        Page<UpmpBMchntBaseInfo> page1 = this.page(page, lambdaQueryWrapper);
        List<UpmpBMchntBaseInfo> listx = page1.getRecords();
        Map<String, Object> maps = new HashMap<String, Object>();
        Map<String, String> map = new HashMap<String, String>();
        List<Object> list = new ArrayList<Object>();
        if (listx != null) {
            for (int i = 0; i < listx.size(); i++) {
                UpmpBMchntBaseInfo info = listx.get(i);
                map = new HashMap<String, String>();
                map.put("name", info.getMchntName());
                map.put("id", info.getMchntNo());
                list.add(map);
            }
            maps.put("results", list);
            maps.put("total", page.getTotal());
            int pageIndex = Common.isBlank(request.getPageNum()) ? 1 : request.getPageNum();
            if (pageIndex == page1.getTotal()) {
                maps.put("more", false);
            } else {
                maps.put("more", true);
            }
        }
        return maps;
    }

    @Override
    public UpmpBMchntBaseInfo getMarchantInfoByMcNo(String instId, String mcNo) {
        LambdaQueryWrapper<UpmpBMchntBaseInfo> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(UpmpBMchntBaseInfo::getInstId, instId).eq(UpmpBMchntBaseInfo::getMchntNo, mcNo);
        return this.baseMapper.selectOne(wrapper);
    }

}
